From 7f62ab1b583f8ea39cc2aad169d98a5c514f40b1 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Thu, 4 Jan 2024 09:04:43 +0100 Subject: [PATCH] fix(medusa-payment-stripe): Fix error handling (#5991) --- .changeset/smart-zoos-nail.md | 6 ++++++ .../medusa-payment-stripe/src/core/stripe-base.ts | 14 +++++++------- .../medusa/src/interfaces/payment-processor.ts | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 .changeset/smart-zoos-nail.md diff --git a/.changeset/smart-zoos-nail.md b/.changeset/smart-zoos-nail.md new file mode 100644 index 0000000000..c8438cb4e8 --- /dev/null +++ b/.changeset/smart-zoos-nail.md @@ -0,0 +1,6 @@ +--- +"@medusajs/medusa": patch +"medusa-payment-stripe": patch +--- + +fix(medusa, medusa-payment-stripe): fix stripe error handling diff --git a/packages/medusa-payment-stripe/src/core/stripe-base.ts b/packages/medusa-payment-stripe/src/core/stripe-base.ts index 454bce3133..0cdd4b2bee 100644 --- a/packages/medusa-payment-stripe/src/core/stripe-base.ts +++ b/packages/medusa-payment-stripe/src/core/stripe-base.ts @@ -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 ?? "", } } } diff --git a/packages/medusa/src/interfaces/payment-processor.ts b/packages/medusa/src/interfaces/payment-processor.ts index 97ac9771e4..fd6cb9ecc7 100644 --- a/packages/medusa/src/interfaces/payment-processor.ts +++ b/packages/medusa/src/interfaces/payment-processor.ts @@ -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 }