Skip to main content
The SDK throws standard JavaScript errors when requests fail. This guide covers common error scenarios and how to handle them.

Basic Error Handling

Wrap API calls in try-catch blocks:

Error Types

Authentication Errors (401)

When your token is invalid or expired:
The onAuthError callback is also triggered:

Not Found Errors (404)

When a resource doesn’t exist:

Validation Errors (400)

When your request data is invalid:

Server Errors (500)

When something goes wrong on the server:

Creating a Robust Error Handler

Retry Logic

For transient failures, implement retry logic:

React Error Handling

With React Query or SWR:

Error Boundaries (React)

Catch errors at the component level:

Logging Errors

For production applications, log errors for debugging:

Best Practices

Never let errors propagate unhandled. At minimum, log them.
Don’t show raw error messages to users. Translate them:
When possible, continue with degraded functionality:
Authentication errors won’t be fixed by retrying:

Authentication

Set up authentication properly.

SDK Overview

Return to SDK basics.