Handling errors

When the PayPal Here SDK encounters an error it returns a PPError object. This object has several properties that provide potentially useful information about the error.

The following sections explain how your app can recognize and respond to various types of errors.

For information about specific errors and recommended responses to them, see the reference documentation for the PayPal Here SDK for Android. Clone the paypal/paypal-here-sdk-android-distribution repository from Android PayPal Here SDK, and load the reference documentation directory page from ./html/index.html.

Error processing best practices

Your error processing design should be guided by the questions:

  • What does this error mean to the user?
  • Can the app resolve it, or at least make it easier for the user to resolve?
  • What can the user do to resolve it?

Depending on the answers to these questions, it may be appropriate for the app to do one or more of these things:

  • Treat the error as an event that is exceptional but not “wrong” (not really an error) and handle it automatically
  • Report the error in terms that are meaningful to the user
  • Offer the user a reasonable set of options for responding
  • Log the error, tell the user that something has gone wrong, and abandon the operation that the app is trying to perform (or some part of it)
  • Do anything else that makes sense for the app and its intended user

The more error conditions the app handles, and the more completely it handles them, the better its user experience will be.

Error handling classes

The PPError class

The PPError class represents a generic error. A DefaultResponseHandler object expects a PPError object as a second parameter; when the object onError method is called, the PPError object provides information about this error.

PPError has two public methods:

  • getDetailedMessage() returns a String describing the error in meaningful terms.
  • getErrorCode() returns an enum value of type T that represents the type of error.

The PPError.BasicErrors class

The PPError.BasicErrors class represents a basic type of error. It has two methods:

  • valueOf() returns a String that indicates a basic type of error. Its value can be NotYetImplemented, Success, and Unknown.
  • values() returns an array of Strings that includes all basic types of errors.