JavaScript SDK - Errors#
Every failure throws a RafikiDBError with fully serializable fields.
Fields#
| Field | Type | Example |
|---|---|---|
message | string | "invalid credentials" |
status | number | 401 |
code | string | "unauthorized" |
errors | string[] | ["Email is required"] |
code is one of: unauthorized, forbidden, not_found, conflict,
invalid_input, quota_exceeded, internal_error.
Handling#
import { RafikiDBError } from '@rafikidb/sdk';
try {
await db.from('profiles').insert({});
} catch (error) {
if (error instanceof RafikiDBError) {
message.error(error.message); // "Nationality is required"
console.error(error.status, error.code, error.errors);
console.log(JSON.stringify(error)); // complete object
} else {
// network errors etc.
}
}
TypeScriptBecause message is enumerable, console.log(error) and JSON.stringify
include it (native Error.message is hidden by default).
Common codes#
| Code | HTTP | Meaning |
|---|---|---|
invalid_input | 400 | Malformed body, missing/invalid field |
unauthorized | 401 | Missing or invalid key / JWT |
forbidden | 403 | Authenticated but not allowed (scope, RLS) |
not_found | 404 | Resource or table does not exist |
conflict | 409 | Duplicate email/phone, conflicting state |
quota_exceeded | 429 | Plan request limit reached |
internal_error | 500 | Server error |
See Error codes for the REST reference.