Skip to content

Commit

Permalink
fix(medusa-payment-stripe): Fix error handling (#5991)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p authored Jan 4, 2024
1 parent 3550750 commit 7f62ab1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/smart-zoos-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"medusa-payment-stripe": patch
---

fix(medusa, medusa-payment-stripe): fix stripe error handling
14 changes: 7 additions & 7 deletions packages/medusa-payment-stripe/src/core/stripe-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ abstract class StripeBase extends AbstractPaymentProcessor {

protected buildError(
message: string,
e: Stripe.StripeRawError | PaymentProcessorError | Error
error: Stripe.StripeRawError | PaymentProcessorError | Error
): PaymentProcessorError {
return {
error: message,
code: "code" in e ? e.code : "",
detail: isPaymentProcessorError(e)
? `${e.error}${EOL}${e.detail ?? ""}`
: "detail" in e
? e.detail
: e.message ?? "",
code: "code" in error ? error.code : "unknown",
detail: isPaymentProcessorError(error)
? `${error.error}${EOL}${error.detail ?? ""}`
: "detail" in error
? error.detail
: error.message ?? "",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/interfaces/payment-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,5 +777,5 @@ export abstract class AbstractPaymentProcessor implements PaymentProcessor {
export function isPaymentProcessorError(
obj: any
): obj is PaymentProcessorError {
return obj && typeof obj === "object" && (obj.error || obj.code || obj.detail)
return obj && typeof obj === "object" && obj.error && obj.code && obj.detail
}

0 comments on commit 7f62ab1

Please sign in to comment.