Skip to content

Error Codes

Each service reports errors in its own shape. The REST API (PostgREST) answers with:

{
"code": "ERROR_CODE",
"message": "Human-readable error description",
"details": "Additional context (if available)",
"hint": "Suggestion for fixing the error (if available)"
}

The auth server answers with { "code": <HTTP status>, "error_code": "...", "msg": "..." }, and the storage service with { "error": "..." } and an HTTP status. The client SDK turns all of them into one SupatypeError (see Client SDK errors).

Database errors (PostgreSQL)

These errors originate from PostgreSQL and are returned by the REST API.

CodeNameDescription
23505unique_violationA row with the same unique key already exists
23503foreign_key_violationReferenced row does not exist in the parent table
23502not_null_violationA required (NOT NULL) column was not provided
23514check_violationA CHECK constraint was violated
42501insufficient_privilegeRow-level security or a missing grant refused the operation
42P01undefined_tableA table named inside a function or view does not exist (a table requested directly is PGRST205)
42703undefined_columnThe requested column does not exist
22P02invalid_text_representationInvalid value for the column type (e.g., text in an integer column)
57014query_canceledQuery was canceled (timeout)

PostgREST errors

CodeHTTP StatusDescription
PGRST000503Could not connect to the database
PGRST001503Could not connect to the database due to an internal error
PGRST002503Could not load the schema cache, for example while an exposed schema does not exist yet
PGRST003504Timed out waiting for a connection from the pool
PGRST100400Invalid query string, such as bad filter syntax
PGRST102400Invalid request body
PGRST106406Schema not found in the exposed schemas
PGRST116406.single() got no rows or more than one
PGRST200400No relationship found for an embedded resource
PGRST204400A column named in the request is not in the schema cache
PGRST205404The requested table is not in the schema cache
PGRST301401JWT could not be decoded or verified: a bad signature, a malformed token, or an empty one
PGRST302401Anonymous request when anonymous access is disabled
PGRST303401JWT claims were rejected, an expired token among them

Gateway errors

On Cloud, before a request reaches /rest/v1, /storage/v1, /realtime/v1 or /functions/v1, the project’s gateway checks its API key and answers { "code": "...", "message": "..." } when it cannot. A local or self-hosted stack does not run this check.

CodeHTTP StatusDescription
no_api_key401The request carried no API key in the apikey header, the bearer token or the apikey query parameter
invalid_api_key401The key was not signed with this project’s JWT secret, or its role is not anon, authenticated or service_role

Auth errors

The auth server sends a machine-readable error_code with each error. The common ones:

CodeDescription
invalid_credentialsWrong email or password
email_not_confirmedThe user has not confirmed their email
user_already_existsA user with this email or phone already exists
email_existsThe email address is already in use
weak_passwordThe password does not meet the requirements
email_address_invalidThe email address is not valid
validation_failedA parameter is missing or malformed
signup_disabledSign-ups are turned off
provider_disabledThe requested OAuth provider is not enabled
over_request_rate_limitRate limit exceeded for this action
over_email_send_rate_limitToo many emails sent
refresh_token_not_foundThe refresh token is invalid
refresh_token_already_usedThe refresh token has already been used
session_not_foundThe session no longer exists
session_expiredThe session has expired
insufficient_aalThe action needs an aal2 (MFA-verified) session
mfa_factor_not_foundThe MFA factor does not exist
mfa_challenge_expiredThe MFA challenge has expired
mfa_verification_failedThe MFA code is incorrect
otp_expiredThe email link or one-time code has expired
invalid_grantThe OAuth token endpoint refused the grant, such as a refresh token already used

Every auth method in the client (sign-up, every sign-in, verifyOtp, resend, resetPasswordForEmail, updateUser, getUser, refreshSession and the MFA methods) copies the code into error.code: error_code from the API’s { code, error_code, msg } body, or error from the OAuth token endpoint’s { error, error_description } body. The numeric code in the first shape is only the HTTP status again, and is in error.status. An error that comes back in a redirect URL (an expired email link) is read by getSessionFromUrl the same way.

Storage errors

The storage service has no error codes of its own: the HTTP status and the message say what went wrong.

HTTP StatusMeaning
400Malformed request (for example, a missing signed-URL token)
401Sign in to perform this action
403Not permitted by the bucket’s access rules, a private bucket read through its public URL, or an invalid or expired signed URL
404The bucket or the object does not exist
409An object already exists at this path (pass upsert: true), or a bucket with this name already exists
413The file exceeds the size limit
415The file type is not allowed for this bucket
507The project’s storage quota is full

Realtime errors

A channel reports trouble through the status passed to its subscribe callback:

StatusDescription
CHANNEL_ERRORThe server answered with an error, such as a refused subscription, or a broadcast or track sent before joining
TIMED_OUTThe connection dropped and the client gave up reconnecting (after 10 attempts)
CLOSEDsupatype.realtime.disconnect() closed the socket

Client SDK errors

The client SDK returns every error as a SupatypeError, a class exported from @supatype/client and a subclass of Error, so error instanceof SupatypeError holds and String(error) reads as its message. Its own fields are message and, when known, code, status, field, hint and details; JSON and spread give exactly those. The errors the SDK throws (NetworkError, RateLimitError, AuthError, PostgrestError, StorageError, RealtimeError and MissingClientValuesError) are SupatypeCodedErrors, a subclass that always has a code and adds a helpUrl; their HTTP status is status too. A request that failed in transit resolves with the NetworkError itself as its error.

import { createClient } from "@supatype/client"
const supatype = createClient({ url: "http://localhost:18473", anonKey: "<anon-key>" })
const { data, error } = await supatype.from("posts").select("*")
if (error) {
console.error(error.code) // "42501"
console.error(error.message) // "new row violates row-level security..."
console.error(error.status) // HTTP status code (e.g., 403)
console.error(error.field) // The column a field validator refused, when one did
}

For a REST error, code is the PostgreSQL or PostgREST code above, exactly as PostgREST 14 sends it: a database error keeps its bare SQLSTATE (23505, never PGRST23505). The PostgREST details and hint are kept as error.details and error.hint when they are non-empty; a unique violation’s details names the key that collided (Key (slug)=(intro) already exists.). When .single() gets no row or more than one, code is PGRST116 and message is Cannot coerce the result to a single JSON object, whether PostgREST or the client noticed.

The client exports the codes it knows as constants, so a comparison is checked by the compiler:

import { PostgrestErrorCodes } from "@supatype/client"
declare const error: { code?: string | undefined } | null
if (error?.code === PostgrestErrorCodes.UNIQUE_VIOLATION) {
// "23505"
}
ConstantCodeWhen
JWT_INVALIDPGRST301The token could not be decoded or verified
JWT_EXPIREDPGRST303The token’s claims were rejected, an expired token among them
PERMISSION_DENIED42501Row-level security or a missing grant refused the operation
NOT_FOUND, MULTIPLE_ROWSPGRST116.single() got no row, or more than one
SCHEMA_CACHE_MISSPGRST204The request named a column the schema cache does not have
UNDEFINED_TABLEPGRST205The table is not in the schema cache
FK_VIOLATION23503Foreign key violation
UNIQUE_VIOLATION23505Unique constraint violation
NOT_NULL_VIOLATION23502Not-null constraint violation
CHECK_VIOLATION23514Check constraint violation
INVALID_INPUT22P02Invalid input syntax for the column type
UNDEFINED_COLUMN42703Undefined column

A request that got no answer at all has one of the client’s own codes:

CodeMeaning
NETWORK_TIMEOUTNo response within the client’s timeout (30000 ms by default)
NETWORK_CONNECTION_REFUSEDThe server refused the connection
NETWORK_DNS_FAILUREThe host name did not resolve
NETWORK_ERRORAny other failure before a response
RATE_LIMITEDA read was still answered 429 after the last retry; status is 429

See Timeouts and retries for which requests are retried.

Handling errors

In application code

const { data, error } = await supatype.from("posts").insert({ title: "Test" }).select()
if (error) {
switch (error.code) {
case "23505":
showNotification("A post with this title already exists")
break
case "42501":
showNotification("You do not have permission to create posts")
break
default:
showNotification("Something went wrong. Please try again.")
console.error(error)
}
return
}

In React

import { useMutation } from "@supatype/react"
export function CreatePost() {
const { mutate, error } = useMutation("posts", "insert")
return (
<>
<button onClick={() => void mutate({ title: "Hello" })}>Create</button>
{error?.code === "23505" && <p>This title is already taken.</p>}
{error?.code === "42501" && <p>You are not allowed to create posts.</p>}
{error && !["23505", "42501"].includes(error.code ?? "") && (
<p>An unexpected error occurred.</p>
)}
</>
)
}