From 5382afccfa0740bba04372a8613c537ff6a69cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frane=20Poli=C4=87?= <16856471+fPolic@users.noreply.github.com> Date: Tue, 26 Aug 2025 20:02:55 +0200 Subject: [PATCH] chore(core-flows): throw Medusa error for exceptions in the fulifllment flows (#13302) Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> --- .changeset/cuddly-baboons-cough.md | 5 +++++ .../src/order/workflows/cancel-order-fulfillment.ts | 3 ++- .../src/order/workflows/create-fulfillment.ts | 3 ++- .../workflows/mark-order-fulfillment-as-delivered.ts | 10 ++++++++-- 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .changeset/cuddly-baboons-cough.md diff --git a/.changeset/cuddly-baboons-cough.md b/.changeset/cuddly-baboons-cough.md new file mode 100644 index 0000000000..3614740ebb --- /dev/null +++ b/.changeset/cuddly-baboons-cough.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +chore(core-flows): throw Medusa error for exceptions in the fulifllment flows diff --git a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts index 13788819ec..99876dc955 100644 --- a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts +++ b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts @@ -103,7 +103,8 @@ export const cancelOrderFulfillmentValidateOrder = createStep( (f) => f.id === input.fulfillment_id ) if (!fulfillment) { - throw new Error( + throw new MedusaError( + MedusaError.Types.INVALID_DATA, `Fulfillment with id ${input.fulfillment_id} not found in the order` ) } diff --git a/packages/core/core-flows/src/order/workflows/create-fulfillment.ts b/packages/core/core-flows/src/order/workflows/create-fulfillment.ts index 13c571cb42..86bb1f42b3 100644 --- a/packages/core/core-flows/src/order/workflows/create-fulfillment.ts +++ b/packages/core/core-flows/src/order/workflows/create-fulfillment.ts @@ -296,7 +296,8 @@ function prepareInventoryUpdate({ if (!reservations?.length) { if (item.variant?.manage_inventory) { - throw new Error( + throw new MedusaError( + MedusaError.Types.INVALID_DATA, `No stock reservation found for item ${item.id} - ${item.title} (${item.variant_title})` ) } diff --git a/packages/core/core-flows/src/order/workflows/mark-order-fulfillment-as-delivered.ts b/packages/core/core-flows/src/order/workflows/mark-order-fulfillment-as-delivered.ts index c9e085c498..d4d38932e3 100644 --- a/packages/core/core-flows/src/order/workflows/mark-order-fulfillment-as-delivered.ts +++ b/packages/core/core-flows/src/order/workflows/mark-order-fulfillment-as-delivered.ts @@ -7,7 +7,12 @@ import { ProductVariantDTO, RegisterOrderDeliveryDTO, } from "@medusajs/framework/types" -import { FulfillmentWorkflowEvents, MathBN, Modules } from "@medusajs/framework/utils" +import { + FulfillmentWorkflowEvents, + MathBN, + MedusaError, + Modules, +} from "@medusajs/framework/utils" import { WorkflowData, WorkflowResponse, @@ -102,7 +107,8 @@ export const orderFulfillmentDeliverablilityValidationStep = createStep( ) if (!orderFulfillment) { - throw new Error( + throw new MedusaError( + MedusaError.Types.INVALID_DATA, `Fulfillment with id ${fulfillment.id} not found in the order` ) }