chore: scope errors on workflow to invoke (#4709)
what: Scopes the errors from the exported workflow to return only invoke errors. If an error occurs on the invoke level, it'll stop the invoke flow and begin the compensation flow. If another error shows up on the compensate level, it doesn't make sense to throw that error since the user won't be able to do anything about it.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { isDefined } from "@medusajs/utils"
|
||||
import { TransactionFlow } from "./transaction-orchestrator"
|
||||
import { TransactionHandlerType, TransactionState } from "./types"
|
||||
|
||||
@@ -108,8 +109,12 @@ export class DistributedTransaction {
|
||||
return this.context
|
||||
}
|
||||
|
||||
public getErrors() {
|
||||
return this.errors
|
||||
public getErrors(handlerType?: TransactionHandlerType) {
|
||||
if (!isDefined(handlerType)) {
|
||||
return this.errors
|
||||
}
|
||||
|
||||
return this.errors.filter((error) => error.handlerType === handlerType)
|
||||
}
|
||||
|
||||
public addError(
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types"
|
||||
import {
|
||||
DistributedTransaction,
|
||||
LocalWorkflow,
|
||||
TransactionHandlerType,
|
||||
TransactionState,
|
||||
TransactionStepError,
|
||||
} from "@medusajs/orchestration"
|
||||
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types"
|
||||
|
||||
import { EOL } from "os"
|
||||
import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { Workflows } from "../definitions"
|
||||
import { EOL } from "os"
|
||||
import { ulid } from "ulid"
|
||||
import { Workflows } from "../definitions"
|
||||
|
||||
export type FlowRunOptions<TData = unknown> = {
|
||||
input?: TData
|
||||
@@ -65,7 +66,7 @@ export const exportWorkflow = <TData = unknown, TResult = unknown>(
|
||||
context
|
||||
)
|
||||
|
||||
const errors = transaction.getErrors()
|
||||
const errors = transaction.getErrors(TransactionHandlerType.INVOKE)
|
||||
|
||||
const failedStatus = [TransactionState.FAILED, TransactionState.REVERTED]
|
||||
if (failedStatus.includes(transaction.getState()) && throwOnError) {
|
||||
|
||||
Reference in New Issue
Block a user