Skip to content

Commit 5499cd2

Browse files
SGFGOVwillbouchcarlos-r-l-rodrigues
authored
fix(core-flows): payment error handling (medusajs#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 <[email protected]> Co-authored-by: Carlos R. L. Rodrigues <[email protected]>
1 parent dc6f253 commit 5499cd2

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.changeset/dirty-radios-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/core-flows": patch
3+
---
4+
5+
fix(core-flows): payment error handling

integration-tests/modules/__tests__/cart/store/carts.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,8 +2168,8 @@ medusaIntegrationTestRunner({
21682168
authorizePaymentSessionSpy.mockImplementation(
21692169
(id, context, sharedContext) => {
21702170
throw new MedusaError(
2171-
MedusaError.Types.INVALID_DATA,
2172-
`Throw a random error`
2171+
MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
2172+
`Payment authorization failed`
21732173
)
21742174
}
21752175
)

packages/core/core-flows/src/payment/steps/authorize-payment-session.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export const authorizePaymentSessionStep = createStep(
5858
logger.error(
5959
`Error was thrown trying to authorize payment session - ${input.id} - ${e}`
6060
)
61+
// this implies the error is already a MedusaError, so we can throw it safely,
62+
if (MedusaError.isMedusaError(e)) {
63+
throw e
64+
}
65+
6166
}
6267

6368
const paymentSession = await paymentModule.retrievePaymentSession(

0 commit comments

Comments
 (0)