Stored procedures already raise exceptions with DETAIL codes, but there is no single,
documented taxonomy for the values or how the API must surface them.
AGENTS.md requires constant error messages, structured context fields, and stable
error mapping for clients and tests.
Decision:
Define a shared error-code taxonomy for indexer stored procedures and API responses:
Stored procedures:
Domain/validation/authorization failures raise ERRCODE = 'P0001' with a constant
MESSAGE of the form Failed to <operation> and DETAIL set to the error code.
Infrastructure/constraint errors use native SQLSTATE codes (e.g., 23505, 23503)
and do not override the Postgres message.
DETAIL values are lower_snake_case, <= 64 chars, and never embed user data.
API responses:
Use RFC9457 Problem responses with constant title/detail strings.
Include error_code (from the DB DETAIL) and sqlstate as context fields when
present, never interpolated into human-readable messages.
Validation errors prefer invalid_params with constant messages; contextual inputs
travel in context fields.
Adopt the following canonical error-code groups (examples are non-exhaustive):