Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

PostgrestError

import { PostgrestError } from "https://esm.sh/@supabase/supabase-js@2.108.1/dist/index.d.mts";

Error format

Returned by every PostgREST request that fails. When something fails, the single most useful field is usually hint — Postgres often returns the actionable fix there, not in message. Always log the full object (e.g. console.error(error)); logging only error.message hides the hint.

Read the fields in roughly this order of usefulness:

  • hint — actionable guidance from the database when available. For permission-denied errors (42501), this is the literal SQL to fix the problem, e.g. "Grant the required privileges to the current role with: GRANT SELECT ON public.users TO anon;". Missing column? hint suggests the column you probably meant. Whenever Postgres knows the fix, it puts it in hint.
  • code — stable error code from PostgREST (e.g. PGRST301) or Postgres (e.g. 42501). Branch on this rather than on message text.
  • details — extra context, often the offending value, key, or row.
  • message — human-readable summary. Useful in UI strings; less useful for debugging.

https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes

class PostgrestError extends Error {
constructor(context: {
message: string;
details: string;
hint: string;
code: string;
}
);
code: string;
details: string;
hint: string;
 
toJSON(): {
name: string;
message: string;
details: string;
hint: string;
code: string;
}
;
}

§Extends

§
Error
[src]

§Constructors

§
new PostgrestError(context: {
message: string;
details: string;
hint: string;
code: string;
}
)
[src]
@example
import PostgrestError from '@supabase/postgrest-js'

throw new PostgrestError({
  message: 'Row level security prevented the request',
  details: 'RLS denied the insert',
  hint: 'Check your policies',
  code: 'PGRST301',
})

§Properties

§
code: string
[src]
§
details: string
[src]
§
hint: string
[src]

§Methods

§
toJSON(): {
name: string;
message: string;
details: string;
hint: string;
code: string;
}
[src]