Error Handling (Driver Layer)#

Driver Layer failures fall into the same three categories as the rest of the stack: retryable, unrecoverable, and OAuth protocol. For the categorization and per-subtype guidance, see Error Handling .

The two platforms surface errors through different idioms — iOS returns Error values via completion handlers; Android throws IdsvrHaapiException. Casting or matching gives you the typed metadata.

Handling Errors#

Completion handlers surface Error values. Cast to HaapiError for the enum, then consult recoverySuggestion for retry guidance:

private func handleError(_ error: Error) {
    guard let haapiError = error as? HaapiError else { return }
    switch haapiError.recoverySuggestion {
    case .retryable(let condition):
        // schedule a retry based on the condition
        break
    case .newHaapiFlow:
        // start a fresh HAAPI flow
        break
    case .nonRecoverable(let action):
        // surface the cause to the user; no retry possible
        break
    }
}

Specific HaapiError cases — attestationFailure, haapiTokenManagerIsClosed, invalidStatusCode, serverError, and others — can be matched directly when their context matters:

switch haapiError {
case .attestationFailure(let cause):
    // attestation rejected — surface to user, do not auto-retry
    break
case .haapiTokenManagerIsClosed:
    // construct a new manager and start over
    break
case .invalidStatusCode(let statusCode):
    // server returned an unexpected status
    break
default:
    break
}

OAuth Protocol Errors#

OAuth protocol errors are returned as part of the response payload from the token endpoint, not as exceptions at the Driver Layer. They surface at the SDK Layer through OAuthTokenManager as ErrorTokenResponse. See OAuthTokenManager for the OAuth-specific handling.

Was this helpful?