Skip to content

Handle Errors

If you get a non-null APayError, then that means something went wrong during the operation. To handle the error, use the response from the ApayError API.

ApayError API

AmazonPayError parser = new AmazonPayError("", "");
AmazonPayError aPayError = parser.fromIntent(data);

// Get Error Type and Error Message
if (aPayError != null) {
       String type = aPayError.getErrorType();
       String message = aPayError.getErrorMessage();
}

Response Parameters

Parameter Description
errorType ErrorType
errorCode String
message String
throwable Throwable

Possible Error Types

Apay Error Type Description
AUTH_ERROR Exception during the authorize phase (e.g., auth code generation failed due to invalid API key)
BROWSING_EXPERIENCE Exception while opening a browser or Custom Tab

Possible Error Code

Apay Error Type Description
START_BROWSING_ERROR Exception during the start operation in browser or Custom Tab
OPERATION_CANCELLED User-initiated cancellation of an operation
ExternalBrowserError Exception while launching a URL in a browser
CustomTabError Exception while launching a URL in a Custom Tab
CustomTabNoSuchMethodError Compatibility issue: The current version of Chrome Custom Tabs used is incompatible with the SDK. Use version 25 or above.

Sample Code to Handle Apay Errors

AmazonPayError parser = new AmazonPayError("", "");
AmazonPayError aPayError = parser.fromIntent(data);

if (aPayError != null) {
    // Get Error Type
    String type = aPayError.getErrorType();
    String message = aPayError.getErrorMessage();
    Log.e(TAG, "SDK Error Received -> Type: " + type + " | Message: " + message); // Inline Logic for Error Types

    if ("AUTH_ERROR".equals(type)) {
          //if the error type is auth error, get the underlaying auth exception
          AuthError authError = aPayError.getAuthError();

          // See the stacktrace associated with the authError (like you wouldn't other exception)
          Log.e(TAG, "Underlying Auth Error: ", authError);
     }
}