http/error_schemas.ts view source
ZodObject<{ error: ZodLiteral<"account_vanished">; }, $loose> 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.
54 declarations
http/error_schemas.ts view source
ZodObject<{ error: ZodLiteral<"account_vanished">; }, $loose> http/error_schemas.ts view source
ZodObject<{ error: ZodLiteral<"actor_not_on_account">; }, $loose> 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.
http/error_schemas.ts view source
ZodObject<{ error: ZodString; }, $loose> Base API error — all JSON error responses have at least {error: string}.
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.
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>>>> __0Partial<Record<number, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>> 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).
authhas_inputbooleanhas_paramsbooleanhas_querybooleanrate_limithttp/error_schemas.ts view source
"account_not_found" Token references a deleted account.
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).
http/error_schemas.ts view source
"actor_not_on_account" Supplied acting field does not name an actor on the authenticated
account.
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.
http/error_schemas.ts view source
"already_bootstrapped" Bootstrap lock already acquired — system already bootstrapped.
http/error_schemas.ts view source
"authentication_required" No valid session or bearer token.
http/error_schemas.ts view source
"bearer_token_rejected_in_browser_context" Bearer token sent with Origin/Referer header (browser context).
http/error_schemas.ts view source
"bootstrap_not_configured" Bootstrap endpoint called but no token path configured.
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.
http/error_schemas.ts view source
"database_connection_failed" Database health-check query failed (connectivity or query error).
http/error_schemas.ts view source
"forbidden_origin" Request origin not in allowlist.
http/error_schemas.ts view source
"forbidden_referer" Request referer not in allowlist.
http/error_schemas.ts view source
"foreign_key_violation" DELETE blocked by a foreign key constraint.
http/error_schemas.ts view source
"insufficient_permissions" Authenticated but missing required role.
http/error_schemas.ts view source
"invalid_credentials" Username or password is wrong (intentionally vague for enumeration prevention).
http/error_schemas.ts view source
"invalid_daemon_token" Daemon token header present but malformed or not matching current/previous token.
http/error_schemas.ts view source
"invalid_event_type" Query parameter event_type is not a valid audit event type.
http/error_schemas.ts view source
"invalid_json_body" Request body is not valid JSON or not an object.
http/error_schemas.ts view source
"invalid_query_params" URL query params failed Zod validation.
http/error_schemas.ts view source
"invalid_request_body" Request body failed Zod validation.
http/error_schemas.ts view source
"invalid_route_params" URL path params failed Zod validation.
http/error_schemas.ts view source
"invalid_token" Bearer token failed validation (missing, malformed, or revoked).
http/error_schemas.ts view source
"invite_account_exists_email" An account already exists with this invite's email.
http/error_schemas.ts view source
"invite_account_exists_username" An account already exists with this invite's username.
http/error_schemas.ts view source
"invite_duplicate" An unclaimed invite already exists for this email or username.
http/error_schemas.ts view source
"invite_not_found" Invite not found (for delete operations).
http/error_schemas.ts view source
"keeper_account_not_configured" Daemon token valid but keeper account not yet resolved (pre-bootstrap).
http/error_schemas.ts view source
"keeper_account_not_found" Keeper account ID set but account row not found.
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.
http/error_schemas.ts view source
"no_matching_invite" No unclaimed invite matches the signup credentials.
http/error_schemas.ts view source
"payload_too_large" Request body exceeds the maximum allowed size.
http/error_schemas.ts view source
"rate_limit_exceeded" Rate limiter rejected the request.
http/error_schemas.ts view source
"role_grant_not_found" Role grant ID not found or not owned by the target actor.
http/error_schemas.ts view source
"role_not_web_grantable" Admin tried to grant a role that is not web-grantable.
http/error_schemas.ts view source
"row_not_found" Row with the given PK value not found.
http/error_schemas.ts view source
"signup_conflict" Signup conflict — username or email already taken (intentionally vague for enumeration prevention).
http/error_schemas.ts view source
"table_no_primary_key" Table has no primary key constraint (cannot delete by PK).
http/error_schemas.ts view source
"table_not_found" Table name not found in information_schema.
http/error_schemas.ts view source
"token_file_missing" Bootstrap token file not found on disk.
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.
http/error_schemas.ts view source
ZodObject<{ error: ZodLiteral<"no_actors_on_account">; }, $loose> 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.
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").
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.
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.
http/error_schemas.ts view source
Partial<Record<number, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>> Error schema map — maps HTTP status codes to Zod schemas.
Used on RouteSpec.errors and internally by derive_error_schemas.
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.