Translates a Postgrex.Error (a Postgres ServerError) into the PostgREST
HTTP response: status code, JSON error envelope, extra response headers, and
an optional custom reason phrase.
This mirrors PostgREST's pgErrorStatus (src/PostgREST/Error.hs) including
the two special SQLSTATE families that give a function full control over the
response:
PTxxx— the digits afterPTare the HTTP status (non-numeric ⇒ 500).PGRST— theMESSAGEis the JSON body envelope and theDETAILis a JSON object{status, status_text, headers}. A malformed/missingMESSAGE/DETAILbecomes aPGRST121parse error.
The returned shape is {status, body, headers, status_text} where body is a
map with string keys "code" | "message" | "details" | "hint", headers is a
list of {name, value} extra headers (e.g. the X-Header from a PGRST
raise), and status_text is nil or a custom reason phrase.
Summary
Functions
Build the {status, body, headers, status_text} tuple for a Postgres server
error. Returns nil if the error carries no Postgres postgres map (a
connection/client error), so callers can fall back to a generic 500.
Types
@type result() :: {status :: pos_integer(), body :: map(), headers :: [{binary(), binary()}], status_text :: binary() | nil}
Functions
@spec translate(Postgrex.Error.t()) :: result() | nil
Build the {status, body, headers, status_text} tuple for a Postgres server
error. Returns nil if the error carries no Postgres postgres map (a
connection/client error), so callers can fall back to a generic 500.