From 5499cd27494a68836a242cd34eb70fe9c141a713 Mon Sep 17 00:00:00 2001 From: Govind <97059996+SGFGOV@users.noreply.github.com> Date: Fri, 7 Nov 2025 18:27:44 +0530 Subject: [PATCH] fix(core-flows): payment error handling (#13876) * fix: payment error handling * Create dirty-radios-kiss.md * fix: updated to use isMedusaError * fix: error message updated and error type corrected --------- Co-authored-by: William Bouchard <46496014+willbouch@users.noreply.github.com> Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com> --- .changeset/dirty-radios-kiss.md | 5 +++++ integration-tests/modules/__tests__/cart/store/carts.spec.ts | 4 ++-- .../src/payment/steps/authorize-payment-session.ts | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/dirty-radios-kiss.md 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(