diff --git a/packages/orchestration/src/transaction/distributed-transaction.ts b/packages/orchestration/src/transaction/distributed-transaction.ts index b4c85c1921..834a53f927 100644 --- a/packages/orchestration/src/transaction/distributed-transaction.ts +++ b/packages/orchestration/src/transaction/distributed-transaction.ts @@ -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( diff --git a/packages/workflows/src/helper/workflow-export.ts b/packages/workflows/src/helper/workflow-export.ts index b77718ba87..cd95087cdb 100644 --- a/packages/workflows/src/helper/workflow-export.ts +++ b/packages/workflows/src/helper/workflow-export.ts @@ -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 = { input?: TData @@ -65,7 +66,7 @@ export const exportWorkflow = ( context ) - const errors = transaction.getErrors() + const errors = transaction.getErrors(TransactionHandlerType.INVOKE) const failedStatus = [TransactionState.FAILED, TransactionState.REVERTED] if (failedStatus.includes(transaction.getState()) && throwOnError) {