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
.notInitializedSDK not initialized before use
.invalidConfigurationInvalid configuration provided
.authenticationFailedAPI key invalid or expired

Session Errors

CodeDescriptionRecoverable
.sessionCreateFailedFailed to create verification session
.sessionNotFoundSession not found or already completed
.sessionExpiredSession has expired✅ (create new)

Channel Errors

CodeDescriptionRecoverable
.qrScanFailedQR code scanning error
.qrInvalidFormatInvalid mDL QR format
.nfcNotSupportedDevice lacks NFC hardware
.nfcNotEnabledNFC is disabled in settings
.nfcReadFailedNFC read error
.bleNotSupportedDevice lacks Bluetooth LE
.bleNotEnabledBluetooth is disabled
.bleConnectionFailedBLE connection error

Verification Errors

CodeDescriptionRecoverable
.deviceResponseInvalidInvalid response from holder's device
.verificationFailedCredential verification failed
.issuerNotTrustedCredential issuer not in trust list
.signatureInvalidCredential signature verification failed
.holderBindingFailedHolder binding verification failed

Network Errors

CodeDescriptionRecoverable
.networkErrorNetwork request failed
.timeoutOperation timed out
.cancelledOperation was cancelled

MDLError Structure

The MDLError struct provides detailed error information:

MDLError.swiftswift
Loading...

Handling Errors

Use Swift's do-catch pattern to handle errors:

ErrorHandling.swiftswift
Loading...

Common Error Constants

The SDK provides pre-defined error instances for convenience:

ErrorConstants.swiftswift
Loading...

SwiftUI Error Handling

Integrate error handling with SwiftUI's alert system:

SwiftUIErrorHandling.swiftswift
Loading...

UIKit Error Handling

UIKitErrorHandling.swiftswift
Loading...

Logging Errors

Enable debug logging for troubleshooting during development:

Logging.swiftswift
Loading...
Warning: Disable debug logging in production builds to avoid exposing sensitive information in logs.

Best Practices

  • Always handle errors – Don't ignore errors. Every async operation should have error handling.
  • Provide user-friendly messages – Translate error codes into messages users can understand and act on.
  • Offer recovery options – For recoverable errors, provide clear paths to retry or resolve the issue.
  • Log for debugging – Log errors during development but be careful about logging in production.
  • Check device capabilities early – Before starting NFC/BLE verification, check if the device supports it.

Related