Error Codes
Asleep.setDebugLoggerDelegate()
let delegate: AsleepDebugLoggerDelegate = self
Asleep.setDebugLoggerDelegate(self)protocol AsleepDebugLoggerDelegate {
func didPrint(message: String)
}| Property Name | Type | Description |
|---|---|---|
| message | String | Log message |
Asleep.setLogger()
You can register the structured logger AsleepLogger. The existing setDebugLoggerDelegate keeps working as before, and new projects can use setLogger.
let logger: AsleepLogger = self
Asleep.setLogger(logger)protocol AsleepLogger {
func d(tag: LogTag, msg: String, error: Error?)
func e(tag: LogTag, msg: String, error: Error?)
func i(tag: LogTag, msg: String, error: Error?)
func w(tag: LogTag, msg: String, error: Error?)
}| Method | Description |
|---|---|
| d | Debug level log |
| e | Error level log |
| i | Info level log |
| w | Warning level log |
Each method receives a LogTag for log categorization (tracking, recording, upload, etc.), a message, and an optional error.
Asleep.AsleepError
enum AsleepError: Error {
case unknown(systemError: Error)
case shouldResume
case over24hours
case audioInitializationFailed
case cannotActivateInBackground
case startTrackingNetworkFail(code: Int, message: String?)
case stopTrackingNetworkFail(code: Int, message: String?)
case responseResult(endpoint: String)
case httpStatus(code: Int, errorCode: Int?, message: String?)
case networkOffline
case configurationError
case alreadyTracking
case sessionCleanupFailed
case sessionCreateFailed
case recorderStartFailed
case trackingStartFailed
case interruptionRecoveryFailed(attemptsCount: Int)
case uploadTrackingTerminated(message: String?)
// v3.3.0
case invalidParameter(message: String?)
case insufficientStorage(message: String?)
case completeTimeout(message: String?)
case saveMetadataFailed(message: String?)
case fetchMetadataFailed(message: String?)
case metadataValidationFailed(message: String?)
case productRegisterFailed(message: String?)
case productRegisterRejected(message: String?)
// v3.3.0 — Token authentication
case tokenIssueFailed(message: String?)
case tokenRefreshFailed(message: String?)
case tokenInvalidCredentials(message: String?)
case tokenNetworkError(message: String?)
}unknown: Unknown system error
- systemError: Error - error due to system
shouldResume: unable to resume microphone recording after interrupt
over24Hours: recording exceeded 24 hours and is forcibly stopped
- The Asleep SDK does not support sleep tracking exceeding 24 hours.
audioInitializationFailed: Audio related hardware setting error
- iOS device audio initialization error
- Call createSleepTrackingManager() again for Audio setting initialization
cannotActivateInBackground: Failed to resume the microphone after the interrupt ends
- If this error occurs, notify the user (e.g., through a notification), and run Asleep.SleepTrackingManager.resumeTracking() while the app is in the foreground.
startTrackingNetworkFail: occurred Network error during startTracking initialization
- code: http codes of 400 and above
- message: String type - description of the error
stopTrackingNetworkFail: occurred Network error during stopTracking
- code: http codes of 400 and above
- message: String type - description of the error
responseResult: error due to api reponse result value
- endpoint - The endpoint where the problem occurred
httpStatus: http error
- code: Int - 400 or more http code
- errorCode: Int? - Since 3.2.0, this carries a 5-digit SDK error code (Beta). For now we recommend branching on the HTTP status code of httpStatus; the full switch to the 5-digit code system is planned for a future release.
- message: String - error reason explanation
Cases added in v3.3.0
| Case | Situation | What the app should do |
|---|---|---|
invalidParameter | Parameter validation failed before sending the request. The start time of the analysis period is later than or equal to the end time | Check the input values |
insufficientStorage | Tracking could not start because there is not enough free space to save the recording files | Guide the user about storage space |
completeTimeout | The analysis was not confirmed as complete within 30 seconds after tracking ended. This is not a tracking failure and the session ends normally | Get it later with report(sessionId:) |
saveMetadataFailed | Failed to save user metadata (network or server error, userId not set) | Retry |
fetchMetadataFailed | Failed to get user metadata (network or server error, userId not set) | Retry |
metadataValidationFailed | A metadata value is out of the allowed range. It is thrown before the server request | Check the input values |
productRegisterFailed | Device (Product) registration temporarily failed. Network error, server error (5xx), or too many requests (429). This is the result after the SDK has retried | Call setup again later |
productRegisterRejected | Device (Product) registration rejected. Invalid input (400), authentication failure (401), or no permission to register (403). Retrying gives the same result | Check productInfo / API Key |
| tokenIssueFailed | Failed to issue the token | Check the network and retry |
| tokenRefreshFailed | Failed to refresh the token | Check the network and retry |
| tokenInvalidCredentials | Invalid appId or appSecret | Check the app credentials; retrying will not help |
| tokenNetworkError | Network error during a token request | Check the network and retry |
The message of each case is for checking the cause (logging) and its wording can change without notice. Always branch your app logic on the case.
How server errors are delivered differs per API.
- Server errors of report queries (
report/reports/averageReport), reanalysis, user deletion and metadata, as well as upload 5xx errors, are delivered ashttpStatus(code:errorCode:message:).- Session creation errors are delivered as
startTrackingNetworkFail, session termination errors asstopTrackingNetworkFail, and upload 4xx errors asuploadTrackingTerminated.Up to v3.3.x this is kept for compatibility with existing clients, and the switch to individual cases is planned for v4.0.0. For now, branch on
code(the HTTP status code).
5-digit SDK error codes (Beta)
Since 3.2.0, a 5-digit SDK error code is delivered in the errorCode of httpStatus (Beta). For now we recommend branching on the HTTP status code; the full switch to the 5-digit code system is planned for a future release.
Reanalyze (30xxx)
| Code | Case | Description |
|---|---|---|
| 30400 | reanalyzeBadRequest | Invalid start_time/end_time |
| 30401 | reanalyzeUnauthorized | Reanalyse unauthorized |
| 30403 | reanalyzeForbidden | The customer is not allowed to reanalyse the session |
| 30404 | reanalyzeNotFound | Sleep session not found |
| 30409 | reanalyzeConflict | Reanalysis is already in progress |
| 30410 | reanalyzeGone | The data retention period has expired |
| 30422 | reanalyzeUnprocessable | The session is still being tracked |
| 30500 | reanalyzeServerError | Reanalyse server error |
SDK basics (11xxx)
| Code | Case | Description |
|---|---|---|
| 11007 | interruptionRecoveryFailed | Failed to recover from interruption (iOS only) |
HTTP Status code
State: COMMON, INIT, TRACKING, REPORT
| Code | Type | Description | State | Handling |
|---|---|---|---|---|
| 401 | Unauthorized | Unauthorized | COMMON | Client Handling |
| 401 | Unauthorized | invalid user id | COMMON | Client Handling |
| 403 | Plan is expired | Plan is expired | COMMON | SDK Stop |
| 403 | Rate limit exceeded | Rate limit exceeded | COMMON | SDK Stop |
| 403 | Quota exceeded | Quota exceeded | COMMON | SDK Stop |
| 400 | Bad Request | Invalid callback url | TRACKING | Client Handling |
| 400 | Bad Request | [WARNING] Invalid session end time. format(YYYY-MM-DDTHH:mm:ssz), 'session_end_time' must always be greater than 'session_start_time’ | TRACKING | SDK Handling |
| 403 | Forbidden | the sleep session is already closed | TRACKING | SDK Stop |
| 404 | Not Found | session does not exist. | TRACKING | Client Handling |
| 409 | Conflict | previous sleep session is not closed yet | TRACKING | SDK Stop |
| 422 | Validation Error | Invalid parameter | TRACKING | SDK Handling |
| 422 | Unprocessable Entity | Invalid parameter. | TRACKING | SDK Handling |
| 400 | Bad Request | invalid timezone | REPORT | Client Handling |
| 400 | Unprocessable Entity | The format of sleep session id {session_id} is not valid | REPORT | Client Handling |
| 401 | Unauthorized | The api key is not provided | REPORT | Client Handling |
| 404 | Not Found | Unable to find the sleep session of id {session_id} | REPORT | Client Handling |
Definition for SDK Error Handling
Definition of SDK Segment Operation
- Init (initAsleepConfig) : SDK Initialization State
- Tracking (SleepTrackingManager): Audio recording environment and server communication protocol management for sleep monitoring
- Report (Reports): Request sleep monitoring results
Error Case Definition
- SDK Stop: Termination process within the SDK. The SDK needs to be restarted for a new start because it is terminated internally. Depending on the status of the SDK, the session and audio recording function are terminated by itself. You need to start from the "initAsleepConfig" request to activate the SDK
- SDK Handling: The SDK updates the error internally and performs the next action. If you want to terminate after receiving an error, you need to handle it depending on the state of the SDK call. To terminate the SDK, you need to call stopTracking only in the Tracking state, and no separate processing is required in other sections
- Client Handling: An error that needs to be handled by the client. Used for error checking during development.
- Do not used: An error that is not used in the current version.
Error Handling Classification
- The error codes that commonly occur when using the SDK are marked in red. The error codes that are crossed out have a low probability of occurring.
Updated 7 days ago
