Bier.ErrorPayload (bier v0.1.0)

Copy Markdown View Source

Serializes PostgREST's error envelope to its exact wire bytes.

Two properties are pinned by the conformance suite and neither survives a plain map encode, so every error body goes through here.

Key emission order is ALPHABETICAL

errorPayload constructs the object as [code, message, details, hint] (Error.hs#L69-L74) but emits it with JSON.encode over an aeson KeyMap (Error.hs#L66). PostgREST pins aeson >= 2.0.3 && < 2.3 and overrides neither postgrest.cabal nor cabal.project for aeson's ordered-keymap flag, whose default is True — so KeyMap is a Data.Map.Strict and the encoder walks its keys in ascending order. The bytes on the wire are therefore {"code":…,"details":…,"hint":…,"message":…}, compact, and NOT in construction order.

Bier's default encoder (Elixir's stdlib JSON, via Bier.json_library/0) preserves neither: a map literal iterates in atom-creation order. The object is assembled here explicitly instead, one Bier.json_library/0-encoded value at a time.

client-error-verbosity

toJsonPgrstError (Error.hs#L69-L78) selects the members: :verbose (the default) emits code, message, details and hint; :minimal emits only code and messagedetails and hint are OMITTED entirely, not set to null. The verbosity is applied once, to every error the request pipeline produces (App.hs#L154), so it governs database errors as much as the PGRSTxxx ones, and Response.hs passes the same setting to the 416 body it builds inline while assembling a normal read response.

Summary

Types

PostgREST's client-error-verbosity setting.

Functions

Encode an error envelope (a map with atom or string keys) into the JSON text PostgREST would put on the wire.

The effective client-error-verbosity for an instance.

Types

verbosity()

@type verbosity() :: String.t()

PostgREST's client-error-verbosity setting.

Functions

encode(body, verbosity)

@spec encode(map(), verbosity()) :: String.t()

Encode an error envelope (a map with atom or string keys) into the JSON text PostgREST would put on the wire.

verbosity_for(instance)

@spec verbosity_for(atom() | nil) :: verbosity()

The effective client-error-verbosity for an instance.

Falls back to the default when the instance cannot be resolved — an error raised before the request was assigned to one still has to be rendered, and every caller wants the same fallback, so it lives here rather than being spelled at each call site.