@@ -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
10095export 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