Error Codes

Asleep.setDebugLoggerDelegate()

let delegate: AsleepDebugLoggerDelegate = self
Asleep.setDebugLoggerDelegate(self)
protocol AsleepDebugLoggerDelegate {
    func didPrint(message: String)
}
Property NameTypeDescription
messageStringLog 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?)
}
MethodDescription
dDebug level log
eError level log
iInfo level log
wWarning 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

CaseSituationWhat the app should do
invalidParameterParameter validation failed before sending the request. The start time of the analysis period is later than or equal to the end timeCheck the input values
insufficientStorageTracking could not start because there is not enough free space to save the recording filesGuide the user about storage space
completeTimeoutThe analysis was not confirmed as complete within 30 seconds after tracking ended. This is not a tracking failure and the session ends normallyGet it later with report(sessionId:)
saveMetadataFailedFailed to save user metadata (network or server error, userId not set)Retry
fetchMetadataFailedFailed to get user metadata (network or server error, userId not set)Retry
metadataValidationFailedA metadata value is out of the allowed range. It is thrown before the server requestCheck the input values
productRegisterFailedDevice (Product) registration temporarily failed. Network error, server error (5xx), or too many requests (429). This is the result after the SDK has retriedCall setup again later
productRegisterRejectedDevice (Product) registration rejected. Invalid input (400), authentication failure (401), or no permission to register (403). Retrying gives the same resultCheck productInfo / API Key
tokenIssueFailedFailed to issue the tokenCheck the network and retry
tokenRefreshFailedFailed to refresh the tokenCheck the network and retry
tokenInvalidCredentialsInvalid appId or appSecretCheck the app credentials; retrying will not help
tokenNetworkErrorNetwork error during a token requestCheck 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 as httpStatus(code:errorCode:message:).
  • Session creation errors are delivered as startTrackingNetworkFail, session termination errors as stopTrackingNetworkFail, and upload 4xx errors as uploadTrackingTerminated.

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)

CodeCaseDescription
30400reanalyzeBadRequestInvalid start_time/end_time
30401reanalyzeUnauthorizedReanalyse unauthorized
30403reanalyzeForbiddenThe customer is not allowed to reanalyse the session
30404reanalyzeNotFoundSleep session not found
30409reanalyzeConflictReanalysis is already in progress
30410reanalyzeGoneThe data retention period has expired
30422reanalyzeUnprocessableThe session is still being tracked
30500reanalyzeServerErrorReanalyse server error

SDK basics (11xxx)

CodeCaseDescription
11007interruptionRecoveryFailedFailed to recover from interruption (iOS only)

HTTP Status code

State: COMMON, INIT, TRACKING, REPORT

CodeTypeDescriptionStateHandling
401UnauthorizedUnauthorizedCOMMONClient Handling
401Unauthorizedinvalid user idCOMMONClient Handling
403Plan is expiredPlan is expiredCOMMONSDK Stop
403Rate limit exceededRate limit exceededCOMMONSDK Stop
403Quota exceededQuota exceededCOMMONSDK Stop
400Bad RequestInvalid callback urlTRACKINGClient Handling
400Bad Request[WARNING] Invalid session end time. format(YYYY-MM-DDTHH:mm:ssz), 'session_end_time' must always be greater than 'session_start_time’TRACKINGSDK Handling
403Forbiddenthe sleep session is already closedTRACKINGSDK Stop
404Not Foundsession does not exist.TRACKINGClient Handling
409Conflictprevious sleep session is not closed yetTRACKINGSDK Stop
422Validation ErrorInvalid parameterTRACKINGSDK Handling
422Unprocessable EntityInvalid parameter.TRACKINGSDK Handling
400Bad Requestinvalid timezoneREPORTClient Handling
400Unprocessable EntityThe format of sleep session id {session_id} is not validREPORTClient Handling
401UnauthorizedThe api key is not providedREPORTClient Handling
404Not FoundUnable to find the sleep session of id {session_id}REPORTClient 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.

Did this page help you?