Skip to main content

Error Handling

Overview

The SDK provides a unified approach to handling errors by throwing a WalletException/WalletError object as a response whenever an error is returned by the Paysafe Wallet SDK.

AndroidiOSDescription
WalletExceptionWalletErrorThe base exception type in Android. The error enum in iOS.
NotConfiguredException.notConfiguredThe configure() method has not been called.
DataException.dataErrorAPI call data-related issue with provided ErrorDetails.
InternalErrorException.internalErrorInternal SDK error with specific reason.
ServiceUnavailableException.serviceUnavailablePaysafe backend is temporary unavailable.
TokenExpiredException.tokenExpiredAccess token has expired.

ErrorDetails

Every DataException/.dataError object has additional information about the specific API error.

FieldDescription
httpStatusThe HTTP status code.
codeSpecific Paysafe error code.
messageDescription of the error.
detailsDetails of any parameter value errors.
fieldErrorsList of field with errors.

Handling Errors

The errors on Android are represented by standard exceptions extended from WalletException class. Surround any SDK operation in runCatching with onSuccess and onFailure:

runCatching {
userService.getProfile(listOf(ProfileIncludes.ACCOUNTS))
}.onSuccess { customerInfo ->
Log.d(TAG, customerInfo.toString())
}.onFailure { exception ->
Log.d(TAG, exception.toString())
}

Try-catch blocks can also be used:

try {
val customerInfo = userService.getProfile(listOf(ProfileIncludes.ACCOUNTS))
Log.d(TAG, customerInfo.toString())
} catch (exception: WalletException){
Log.d(TAG, exception.toString())
}