Skip to content

Commit ce2c16d

Browse files
authored
Merge pull request #28 from lambda-curry/mohsen/360t-898-braintree-fraud-detection-cases-are-not-covered
refactor: improve error handling in createTransaction
2 parents 265d98e + 6f6b44e commit ce2c16d

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ const validateString = (value: unknown, fieldName: string): string => {
9191
return value;
9292
};
9393

94-
const validateOptionalString = (value: unknown, fieldName: string): string | undefined => {
95-
if (value === undefined || value === null) return undefined;
96-
return validateString(value, fieldName);
97-
};
98-
9994
// Error handling utility that preserves full error context
10095
export const buildBraintreeError = (
10196
error: unknown,
@@ -300,10 +295,11 @@ class BraintreeBase extends AbstractPaymentProvider<BraintreeOptions> {
300295
if (!sessionData.payment_method_nonce)
301296
throw new MedusaError(MedusaError.Types.INVALID_ARGUMENT, 'Payment method nonce is required');
302297

303-
if (!transaction)
298+
if (!transaction) {
304299
transaction = await this.createTransaction({
305300
input,
306301
});
302+
}
307303

308304
const paymentStatusRequest: GetPaymentStatusInput = {
309305
...input,
@@ -326,7 +322,7 @@ class BraintreeBase extends AbstractPaymentProvider<BraintreeOptions> {
326322
};
327323
} catch (error) {
328324
this.logger.error(`Error authorizing transaction: ${error.message}`, error);
329-
throw new MedusaError(MedusaError.Types.INVALID_DATA, `Failed to authorize transaction`);
325+
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.message ?? 'Unknown error');
330326
}
331327
}
332328

@@ -516,7 +512,7 @@ class BraintreeBase extends AbstractPaymentProvider<BraintreeOptions> {
516512
if (!saleResponse.success) {
517513
throw new MedusaError(
518514
MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
519-
`Failed to create Braintree transaction: ${JSON.stringify(saleResponse)}`,
515+
saleResponse.transaction?.gatewayRejectionReason ?? 'Unknown error',
520516
);
521517
}
522518

0 commit comments

Comments
 (0)