How stitchdb-js reports errors: { data, error } results, error classes and status codes.
Calls don't throw for API errors: they resolve to { data, error }. Check error first.
JavaScript
const { data, error } = await stitchdb.from('todos').insert({ task: '' }).select()
if (error) {
console.error(error.code, error.message, error.details, error.hint)
return
}#By service
| Service | Error | Fields |
|---|---|---|
Database (from, rpc) | PostgrestError | message, code (Postgres SQLSTATE such as 23505 or an API code such as PGRST116), details, hint; the HTTP status is on the result as status |
| Auth | AuthError (AuthApiError, AuthSessionMissingError, AuthWeakPasswordError, ...) | message, status, code (for example invalid_credentials, email_not_confirmed, over_request_rate_limit) |
| Storage | StorageError | message, statusCode |
| Edge Functions | FunctionsHttpError, FunctionsRelayError, FunctionsFetchError | message, context (the Response) |
| Realtime | subscribe status CHANNEL_ERROR / TIMED_OUT | the second argument of the subscribe() callback |
#Throwing instead
JavaScript
try {
const { data } = await stitchdb.from('todos').select().throwOnError()
} catch (e) {
// PostgrestError
}#Common status codes
| Status | Meaning |
|---|---|
401 | Missing or invalid API key, or an expired user token (the client refreshes it automatically) |
403 / 42501 | Row Level Security or a missing grant blocked the request |
402 | A quota of your plan is used up (code: "quota_exceeded") |
404 | Unknown table, function or file |
405 | A write was sent to a read-only replica endpoint (code: "read_only_replica") |
409 | Unique or foreign key conflict |
429 | Rate limited: retry after the Retry-After header |