On this page

Errors

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

ServiceErrorFields
Database (from, rpc)PostgrestErrormessage, code (Postgres SQLSTATE such as 23505 or an API code such as PGRST116), details, hint; the HTTP status is on the result as status
AuthAuthError (AuthApiError, AuthSessionMissingError, AuthWeakPasswordError, ...)message, status, code (for example invalid_credentials, email_not_confirmed, over_request_rate_limit)
StorageStorageErrormessage, statusCode
Edge FunctionsFunctionsHttpError, FunctionsRelayError, FunctionsFetchErrormessage, context (the Response)
Realtimesubscribe status CHANNEL_ERROR / TIMED_OUTthe second argument of the subscribe() callback

#Throwing instead

JavaScript
try {
  const { data } = await stitchdb.from('todos').select().throwOnError()
} catch (e) {
  // PostgrestError
}

#Common status codes

StatusMeaning
401Missing or invalid API key, or an expired user token (the client refreshes it automatically)
403 / 42501Row Level Security or a missing grant blocked the request
402A quota of your plan is used up (code: "quota_exceeded")
404Unknown table, function or file
405A write was sent to a read-only replica endpoint (code: "read_only_replica")
409Unique or foreign key conflict
429Rate limited: retry after the Retry-After header