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
#

45 declarations

view source

ApiError
#

derive_error_schemas
#

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)

auth

the route's auth requirement

has_input

whether the route has a non-null input schema

type boolean

has_params

whether the route has a params schema

type boolean
default false

has_query

whether the route has a query schema

type boolean
default false

rate_limit?

the rate limit key type, if any

type RateLimitKey | undefined
optional

returns

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

error schemas keyed by HTTP status code

ERROR_ACCOUNT_NOT_FOUND
#

ERROR_ALREADY_BOOTSTRAPPED
#

ERROR_AUTHENTICATION_REQUIRED
#

ERROR_BEARER_REJECTED_BROWSER
#

ERROR_BOOTSTRAP_NOT_CONFIGURED
#

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_MISSING_IDENTIFIER
#

ERROR_INVITE_NOT_FOUND
#

ERROR_KEEPER_ACCOUNT_NOT_CONFIGURED
#

ERROR_KEEPER_ACCOUNT_NOT_FOUND
#

ERROR_KEEPER_REQUIRES_DAEMON_TOKEN
#

ERROR_NO_MATCHING_INVITE
#

ERROR_PAYLOAD_TOO_LARGE
#

ERROR_PERMIT_NOT_FOUND
#

ERROR_RATE_LIMIT_EXCEEDED
#

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.

KeeperError
#

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_role: ZodString; }, $loose>

Permission error — returned by require_role() when the required role is missing.

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

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)

RouteErrorSchemas
#

ValidationError
#

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.

Imported by
#