Error Handling

Handle errors gracefully and provide a good user experience when issues occur.

Error Codes

The SDK uses typed error codes to help you identify and handle specific error conditions. Some errors are recoverable (can be retried), while others require user action or indicate permanent failures.

Initialization Errors

CodeDescriptionRecoverable
NOT_INITIALIZEDSDK not initialized before use
INVALID_CONFIGInvalid configuration provided
AUTHENTICATION_FAILEDAPI key invalid or expired

Session Errors

CodeDescriptionRecoverable
SESSION_CREATE_FAILEDFailed to create verification session
SESSION_NOT_FOUNDSession not found or already completed
SESSION_EXPIREDSession has expired✅ (create new)

Channel Errors

CodeDescriptionRecoverable
QR_SCAN_FAILEDQR code scanning error
QR_INVALID_FORMATInvalid mDL QR format
NFC_NOT_SUPPORTEDDevice lacks NFC hardware
NFC_NOT_ENABLEDNFC is disabled in settings
NFC_READ_FAILEDNFC read error
BLE_NOT_SUPPORTEDDevice lacks Bluetooth LE
BLE_NOT_ENABLEDBluetooth is disabled
BLE_CONNECTION_FAILEDBLE connection error

Verification Errors

CodeDescriptionRecoverable
DEVICE_RESPONSE_INVALIDInvalid response from holder's device
VERIFICATION_FAILEDCredential verification failed
ISSUER_NOT_TRUSTEDCredential issuer not in trust list
SIGNATURE_INVALIDCredential signature verification failed
HOLDER_BINDING_FAILEDHolder binding verification failed

Network Errors

CodeDescriptionRecoverable
NETWORK_ERRORNetwork request failed
TIMEOUTOperation timed out
CANCELLEDOperation was cancelled

Handling Errors

Use the fold pattern to handle success and failure cases:

ErrorHandling.ktkotlin
Loading...

MDLException Properties

The MDLException class provides detailed error information:

MDLException.ktkotlin
Loading...

Common Error Scenarios

SDK Not Initialized

InitializationError.ktkotlin
Loading...

Device Capability Checks

CapabilityChecks.ktkotlin
Loading...

Network Retry Logic

RetryLogic.ktkotlin
Loading...

User-Friendly Error Messages

Translate error codes into user-friendly messages:

UserFriendlyMessages.ktkotlin
Loading...

Logging and Debugging

Enable debug logging during development to troubleshoot issues:

DebugLogging.ktkotlin
Loading...
Warning: Never enable debug logging in production builds. It may expose sensitive information in device logs.