http/error_schemas.ts view source
ZodObject<{ error: ZodString; }, $loose> Base API error — all JSON error responses have at least {error: string}.
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.
45 declarations
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
(auth: RouteAuth, has_input: boolean, has_params?: boolean, has_query?: boolean, rate_limit?: RateLimitKey | undefined): Partial<Record<number, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>> 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:
- Has input schema (non-null) or has params schema or has query schema: 400 (validation error with issues)
- auth: authenticated: 401
- auth: role: 401 + 403 (with required_role)
- auth: keeper: 401 + 403 (keeper-specific)
- rate_limit: 429 (rate limit exceeded with retry_after)
auththe route's auth requirement
has_inputwhether the route has a non-null input schema
booleanhas_paramswhether the route has a params schema
booleanfalsehas_querywhether the route has a query schema
booleanfalserate_limit?the rate limit key type, if any
RateLimitKey | undefinedPartial<Record<number, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>> error schemas keyed by HTTP status code
http/error_schemas.ts view source
"account_not_found" Token references a deleted account.
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
"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_missing_identifier" Invite must have at least an 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
"keeper_requires_daemon_token" Keeper routes require daemon_token credential type.
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
"permit_not_found" Permit ID not found or not owned by the target actor.
http/error_schemas.ts view source
"rate_limit_exceeded" Rate limiter rejected the request.
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<"keeper_requires_daemon_token">; credential_type: ZodString; }, $loose> Keeper credential error — returned by require_keeper when credential type is wrong.
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_role: ZodString; }, $loose> Permission error — returned by require_role() when the required role is missing.
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
RateLimitKey Rate limit key type — declares what a route's rate limiter is keyed on.
- 'ip' — per-IP rate limiting (bootstrap, password change, bearer auth)
- 'account' — per-account rate limiting (keyed on submitted identifier)
- 'both' — both per-IP and per-account (login)
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: ZodString; issues: ZodArray<ZodObject<{ code: ZodString; message: ZodString; path: ZodArray<ZodUnion<readonly [ZodString, ZodNumber]>>; }, $loose>>; }, $loose> Input validation error — returned when the request body fails Zod parsing.
issues contains the Zod validation issues for diagnostic display.