http/error_schemas.ts

Standard error response schemas and error code constants for fuz_app routes.

Defines ERROR_* constants (single source of truth for machine-parseable error codes), Zod schemas for error response shapes, a type for error schema maps, and derive_error_schemas to auto-populate middleware-produced errors from a route's auth requirement and input schema.

Used in RouteSpec.errors and MiddlewareSpec.errors for surface introspection and DEV-mode validation.

Declarations
#

54 declarations

view source

AccountVanishedError
#

ActorNotOnAccountError
#

ActorRequiredError
#

http/error_schemas.ts view source

ZodObject<{ error: ZodLiteral<"actor_required">; available: ZodArray<ZodObject<{ id: ZodString; name: ZodString; }, $loose>>; }, $loose>

Authorization-phase failure shapes. Surfaced when the dispatcher's apply_authorization_phase rejects a request before the handler runs — the route is acting-aware (input declares acting?: ActingActor or auth requires role_grants), but actor resolution failed.

400: actor_required (with available[]) for unspecified-actor on a multi-actor account; actor_not_on_account for a supplied actor id that doesn't belong to the authenticated account.

500: no_actors_on_account for a signup-invariant violation (the actor list enumerated empty); account_vanished for a torn-read race (account/actor row deleted between credential validation and the dispatcher's follow-up read).

Used by derive_error_schemas when auth.actor !== 'none' so the merged error surface matches what the dispatcher actually emits.

ApiError
#

CredentialTypeRequiredError
#

http/error_schemas.ts view source

ZodObject<{ error: ZodLiteral<"credential_type_required">; required_credential_types: ZodReadonly<ZodArray<ZodString>>; }, $loose>

Credential-type error — returned by the dispatcher's post-authorization credential gate (and the require_credential_types REST middleware) when the request's credential type isn't in the route's auth.credential_types allowlist.

required_credential_types carries what the route declared (['daemon_token'] for keeper; future gates carry their own labels). Symmetric with PermissionError's required_roles: clients see what the route demanded, not what their credential is.

derive_error_schemas
#

http/error_schemas.ts view source

({ auth, has_input, has_params, has_query, rate_limit, }: DeriveErrorSchemasOptions): Partial<Record<number, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>>

__0

returns

Partial<Record<number, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>>

DeriveErrorSchemasOptions
#

http/error_schemas.ts view source

DeriveErrorSchemasOptions

Derive error schemas from a route's auth requirement, input schema, and rate limit config.

Returns the error schemas that middleware will auto-produce for this route. Route handlers can declare additional error schemas via RouteSpec.errors; explicit entries override auto-derived ones for the same status code.

Derivation rules under the new flat-record auth shape: - Has input / params / query schema: 400 (ValidationError). - auth.account === 'required' or auth.actor === 'required': 401 (ApiError) — pre-validation 401 fires when the credential isn't there. 'optional' does not derive 401. - auth.roles?.length: 403 (PermissionError carrying required_roles). - auth.credential_types?.length: 403 (CredentialTypeRequiredError carrying required_credential_types — symmetric with PermissionError). Today the only credential gate is keeper; future gates reuse the literal. - auth.actor !== 'none' ('optional' or 'required'): extends 400 with ActorRequiredError / ActorNotOnAccountError and adds 500 union of NoActorsOnAccountError / AccountVanishedError. The dispatcher's authorization phase emits these whenever it tries to resolve an actor. - rate_limit: 429 (RateLimitError with retry_after).

auth

has_input

type boolean

has_params

type boolean

has_query

type boolean

rate_limit

ERROR_ACCOUNT_NOT_FOUND
#

ERROR_ACCOUNT_VANISHED
#

http/error_schemas.ts view source

"account_vanished"

Authentication validated an account, but a follow-up read in the authorization phase came back null — the account or its named actor row was deleted between the credential check and the dispatcher's build_request_context / build_account_context step. Torn read, not a missing-actor invariant violation. Surfaced as 500 so the operator sees the race signal; clients can retry. Distinct from ERROR_ACCOUNT_NOT_FOUND (stale token referencing a long-deleted account, raised at credential validation) and ERROR_NO_ACTORS_ON_ACCOUNT (the actor list enumerated empty).

ERROR_ACTOR_NOT_ON_ACCOUNT
#

ERROR_ACTOR_REQUIRED
#

http/error_schemas.ts view source

"actor_required"

Multi-actor account requires the request to carry an explicit acting field naming the actor the request is acting as, so the dispatcher's authorization phase doesn't pick a default actor silently. Returned with the available actors so the client can prompt.

ERROR_ALREADY_BOOTSTRAPPED
#

ERROR_AUTHENTICATION_REQUIRED
#

ERROR_BEARER_REJECTED_BROWSER
#

ERROR_BOOTSTRAP_NOT_CONFIGURED
#

ERROR_CREDENTIAL_TYPE_REQUIRED
#

http/error_schemas.ts view source

"credential_type_required"

Route requires a credential type the request didn't arrive on. Symmetric with ERROR_INSUFFICIENT_PERMISSIONS + required_roles: the body carries required_credential_types: ReadonlyArray<string> — what the route demanded, not what arrived. Today the only credential gate is keeper (['daemon_token']); future gates (agent_token, group_actor_token) reuse the same literal and label themselves through the array.

ERROR_DATABASE_CONNECTION_FAILED
#

ERROR_FORBIDDEN_ORIGIN
#

ERROR_FORBIDDEN_REFERER
#

ERROR_FOREIGN_KEY_VIOLATION
#

ERROR_INSUFFICIENT_PERMISSIONS
#

ERROR_INVALID_CREDENTIALS
#

ERROR_INVALID_DAEMON_TOKEN
#

ERROR_INVALID_EVENT_TYPE
#

ERROR_INVALID_JSON_BODY
#

ERROR_INVALID_QUERY_PARAMS
#

ERROR_INVALID_REQUEST_BODY
#

ERROR_INVALID_ROUTE_PARAMS
#

ERROR_INVALID_TOKEN
#

ERROR_INVITE_ACCOUNT_EXISTS_EMAIL
#

ERROR_INVITE_ACCOUNT_EXISTS_USERNAME
#

ERROR_INVITE_DUPLICATE
#

ERROR_INVITE_NOT_FOUND
#

ERROR_KEEPER_ACCOUNT_NOT_CONFIGURED
#

ERROR_KEEPER_ACCOUNT_NOT_FOUND
#

ERROR_NO_ACTORS_ON_ACCOUNT
#

http/error_schemas.ts view source

"no_actors_on_account"

Authenticated account exists but has no actors. Server invariant violation — signup / bootstrap always create an actor in the same transaction. Surfaced from the dispatcher's authorization phase as a 500 so the operator sees the corruption signal rather than a confusing 4xx. Distinct from ERROR_ACCOUNT_VANISHED: the actor list was enumerated successfully and came back empty.

ERROR_NO_MATCHING_INVITE
#

ERROR_PAYLOAD_TOO_LARGE
#

ERROR_RATE_LIMIT_EXCEEDED
#

ERROR_ROLE_GRANT_NOT_FOUND
#

ERROR_ROLE_NOT_WEB_GRANTABLE
#

ERROR_ROW_NOT_FOUND
#

ERROR_SIGNUP_CONFLICT
#

ERROR_TABLE_NO_PRIMARY_KEY
#

ERROR_TABLE_NOT_FOUND
#

ERROR_TOKEN_FILE_MISSING
#

ForeignKeyError
#

http/error_schemas.ts view source

ZodObject<{ error: ZodLiteral<"foreign_key_violation">; }, $loose>

Foreign key violation error — returned when a delete is blocked by references.

NoActorsOnAccountError
#

PayloadTooLargeError
#

http/error_schemas.ts view source

ZodObject<{ error: ZodLiteral<"payload_too_large">; }, $loose>

Payload too large error — returned when the request body exceeds the size limit.

PermissionError
#

http/error_schemas.ts view source

ZodObject<{ error: ZodLiteral<"insufficient_permissions">; required_roles: ZodReadonly<ZodArray<ZodString>>; }, $loose>

Permission error — returned by require_role() and the dispatcher's post-authorization role gate when the actor's role_grants don't include any of the route's auth.roles.

required_roles carries the full disjunction the route declared (auth.roles from the new flat-record shape). Single-role specs surface as a one-element array; multi-role disjunctions show every admittable role so clients can render targeted copy ("requires admin or steward").

RateLimitError
#

http/error_schemas.ts view source

ZodObject<{ error: ZodLiteral<"rate_limit_exceeded">; retry_after: ZodNumber; }, $loose>

Rate limit error — returned when a rate limiter rejects the request.

RateLimitKey
#

http/error_schemas.ts view source

ZodEnum<{ both: "both"; account: "account"; ip: "ip"; }>

Rate limit key type — declares what a route or RPC action's rate limiter is keyed on.

- 'ip' — per-IP rate limiting (bootstrap, password change, bearer auth) - 'account' — per-account rate limiting. On REST auth routes the key is the submitted identifier (login). On RPC actions (post-auth) the key is the resolved actor id (request_context.actor.id) — separate namespace. - 'both' — both keys.

RouteErrorSchemas
#

ValidationError
#

http/error_schemas.ts view source

ZodObject<{ error: ZodEnum<{ invalid_request_body: "invalid_request_body"; invalid_json_body: "invalid_json_body"; invalid_route_params: "invalid_route_params"; invalid_query_params: "invalid_query_params"; }>; issues: ZodOptional<...>; }, $loose>

Input validation error — returned when params / query / body fails Zod parsing, or when the request body is not valid JSON.

error is one of the four validation codes the framework emits. issues carries Zod's validation issues for diagnostic display on the three schema-failure cases (invalid_request_body, invalid_route_params, invalid_query_params). The invalid_json_body case (request body parse failure or non-object root) emits no issues, so the field is optional.

Depends on
#

Imported by
#