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:
Riqwan Thamir authored and GitHub committed 2023-08-07 17:02:38 +00:00
1 parent 8ae31aff4b
commit a42c41e8ab
2 files changed
+12 -6

No files matched your search

@@ -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) {