Skip to content

loadPayPalSDK() Promise doesn't reject on network errors #740

@vbsixt

Description

@vbsixt

Description

When using paypalCheckoutInstance.loadPayPalSDK(), network errors (such as 400 Bad Request) don't cause the returned Promise to reject. This makes it impossible to properly handle SDK loading failures in try/catch blocks or with Promise error handlers.

Current Behavior

When the PayPal SDK fails to load with network errors, the Promise from loadPayPalSDK():

  1. Never resolves or rejects (hangs indefinitely)
  2. Fails silently without throwing a proper error

Expected Behavior

The Promise returned by loadPayPalSDK() should reject with an appropriate error when the SDK fails to load, allowing developers to handle these errors using standard Promise error handling patterns.

Code Example

try {
  // This Promise never rejects on network errors
  await paypalCheckoutInstance.loadPayPalSDK({
    'client-id': client_id,
    currency,
    intent: 'capture',
    commit: false,
    locale,
  });
  
  // Further code is never executed on network errors
  const buttons = window.paypal.Buttons({
    // Configuration...
  });
} catch (error) {
  // This catch block never executes on network errors
  console.error('PayPal SDK loading error:', error);
}

Proposed Solution

Update the internal loadScript utility to properly reject the Promise when there's a network error loading the PayPal SDK.

Environment

  • braintree-web version: 3.117.1
  • Browser: Chrome, Firefox, Safari (all affected)
  • OS: Windows, macOS, Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions