Skip to main content

Error handling

All SDK calls throw EkycError on failure. Catch and inspect:

try {
final r = await sdk.liveness.check(/* ... */);
} on EkycError catch (e) {
print('ekyc: ${e.code} (request_id=${e.requestId}): ${e.message}');
}

Fields

FieldTypeNotes
codeStringMaps to error.type in the wire envelope
messageStringHuman-readable summary
statusCodeint?HTTP status; null for pre-flight errors
requestIdString?The gateway's request_id. Quote in support tickets.
paramString?For validation_failed, names the offending field
docUrlString?Link to a docs page documenting the error
retryAfterDuration?For rate_limited, how long to wait
causeObject?Wrapped underlying exception (network errors)

Sentinel constants

EkycErrorCode.* exposes the strings:

import 'package:ekyc_sdk/ekyc_sdk.dart' show EkycErrorCode;

// EkycErrorCode.tokenExpired == 'token_expired'
// EkycErrorCode.invalidCredentials == 'invalid_credentials'
// EkycErrorCode.rateLimited == 'rate_limited'
// EkycErrorCode.validationFailed == 'validation_failed'
// EkycErrorCode.networkError == 'network_error'
// EkycErrorCode.tokenProviderFailed == 'token_provider_failed'
// EkycErrorCode.cameraPermissionRequired == 'camera_permission_required'

See Errors and retries for the full list.

tokenProvider failures

If your tokenProvider callback throws (e.g. your backend is down), the SDK wraps the underlying exception:

final sdk = EkycSdk(EkycConfig(
tokenProvider: () async {
throw Exception('backend unreachable');
},
));

try {
await sdk.sessions.create(customerRef: 'x');
} on EkycError catch (e) {
e.code // 'token_provider_failed'
e.cause // Exception: backend unreachable
}

The SDK does not retry your tokenProvider. That's your responsibility — add retry logic, circuit breakers, etc. inside the callback.