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` ) }