Skip to main content
The SDK uses a consistent error-handling approach to make it easy to detect, differentiate, and respond to different types of issues. Errors are categorized into three types:
  1. Warnings: Non-critical issues that do not interrupt normal execution. These are logged to the console using console.warn() or console.error(), depending on severity.
  2. Unexpected Errors: Indicate incorrect or unsupported use of the SDK. These are thrown as standard JavaScript Error instances with descriptive messages to help identify the problem.
  3. API Errors: Occur when a request to Smile’s API fails. These are thrown as ApiError instances, which extend the native Error class and include additional details about the HTTP response and API context (see ApiError object).

Determining the type of error

The best way to differentiate between the two types of error objects that may be thrown depends on your build environment:
  • In a typed environment, use ApiError.isApiError().
  • In a non-typed environment, check for the presence of a status property on the error object. If it’s present and has a numeric value, then it’s an API error.

Error handling example

// In plain JavaScript
try { ... } catch (error) {
  if (error && typeof error === 'object' && typeof error.status === 'number') {
    // Handle API error
  } else {
    // Handle unexpected error
  }
}