EncoreError
Represents the errors that can occur when using the Encore SDK. Handle these errors gracefully to provide a good user experience.Definition
Error Cases
| Error | Associated Values | Description |
|---|---|---|
.notInitialized | None | SDK not configured. Call Encore.shared.configure(apiKey:) at launch. |
.userIdNotAvailable | None | User ID required but missing. Rare - SDK auto-generates anonymous IDs. |
.networkError | Error | Network connection issue (no internet, timeout, connection failed). |
.decodingError | Error | Response parsing failed (unexpected format or structure). |
.invalidURL | None | URL construction failed (malformed API endpoint). |
.unknown | None | Unexpected system error with no specific cause identified. |
.serverResponse | String | Server returned an error response with a message. |
.httpError | statusCode: Int, message: String? | HTTP status error (4xx/5xx responses from server). |
.apiError | code: String?, message: String | API returned an error response (validation or business logic error). |
Usage
Error Handling Best Practices
1. Always Handle Errors Gracefully
2. Distinguish Between User Actions and Errors
3. Provide Fallback Behavior
Related Types
- NotGrantedReason - Detailed reasons for not being granted
- EncorePresentationResult - Overall presentation outcome
Never block user actions due to SDK errors. Always provide a fallback path that allows users to complete their intended action.
Most errors are rare. The most common “error” is actually the user declining an offer, which is normal behavior and should be handled as such through
NotGrantedReason, not as an error.