diff --git a/.changeset/dirty-radios-kiss.md b/.changeset/dirty-radios-kiss.md new file mode 100644 index 0000000000..6eb69437cb --- /dev/null +++ b/.changeset/dirty-radios-kiss.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +fix(core-flows): payment error handling diff --git a/integration-tests/modules/__tests__/cart/store/carts.spec.ts b/integration-tests/modules/__tests__/cart/store/carts.spec.ts index 110dfbc568..54a038e20c 100644 --- a/integration-tests/modules/__tests__/cart/store/carts.spec.ts +++ b/integration-tests/modules/__tests__/cart/store/carts.spec.ts @@ -2168,8 +2168,8 @@ medusaIntegrationTestRunner({ authorizePaymentSessionSpy.mockImplementation( (id, context, sharedContext) => { throw new MedusaError( - MedusaError.Types.INVALID_DATA, - `Throw a random error` + MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR, + `Payment authorization failed` ) } ) diff --git a/packages/core/core-flows/src/payment/steps/authorize-payment-session.ts b/packages/core/core-flows/src/payment/steps/authorize-payment-session.ts index fc69ba04c8..80f9dcf37d 100644 --- a/packages/core/core-flows/src/payment/steps/authorize-payment-session.ts +++ b/packages/core/core-flows/src/payment/steps/authorize-payment-session.ts @@ -58,6 +58,11 @@ export const authorizePaymentSessionStep = createStep( logger.error( `Error was thrown trying to authorize payment session - ${input.id} - ${e}` ) + // this implies the error is already a MedusaError, so we can throw it safely, + if (MedusaError.isMedusaError(e)) { + throw e + } + } const paymentSession = await paymentModule.retrievePaymentSession(