fix(medusa-payment-stripe): Fix error handling (#5991)

This commit is contained in:
Adrien de Peretti
2024-01-04 09:04:43 +01:00
committed by GitHub
parent 3550750975
commit 7f62ab1b58
3 changed files with 14 additions and 8 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"medusa-payment-stripe": patch
---
fix(medusa, medusa-payment-stripe): fix stripe error handling

View File

@@ -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 ?? "",
}
}
}

View File

@@ -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
}