http/route_errors.ts

A route's error map: every error definition it can answer with — derived from its slots (derive_route_errors), declared by each middleware layer that runs on it, and its own errors — and the status map they group into.

Built once per app (resolve_app_route_error_maps, carried as AppSurfaceSpec.route_error_maps) and read by every reader of a route's declared errors: the surface, the DEV error check, the test helpers, error coverage, and the attack-surface suite. The maps are keyed METHOD path (format_route_key).

view source

Declarations
#

5 declarations

get_route_error_map
#

http/route_errors.ts view source

(route_error_maps: ReadonlyMap<string, RouteErrorMap> | null | undefined, spec: RouteErrorMapSpec): RouteErrorMap import {get_route_error_map} from '@fuzdev/fuz_app/http/route_errors.js';

A route's error map from a map built by resolve_app_route_error_maps, or, with no map, resolved from the route alone — without middleware.

route_error_maps

the app's route error maps, if the caller has them

type ReadonlyMap<string, RouteErrorMap> | null | undefined

spec

the route spec

returns

RouteErrorMap

the route's error map

throws

  • Error - naming the route's key when a map is given with no entry for the route — a map built over other routes, which would silently drop the middleware's definitions

resolve_app_route_error_maps
#

http/route_errors.ts view source

(route_specs: readonly RouteErrorMapSpec[], middleware_specs?: readonly Pick<MiddlewareSpec, "path" | "errors" | "carve_outs">[] | null | undefined): Map<...> import {resolve_app_route_error_maps} from '@fuzdev/fuz_app/http/route_errors.js';

Resolve every route's error map (resolve_route_error_map) against one middleware list, keyed by format_route_key (METHOD path).

route_specs

the app's routes

type readonly RouteErrorMapSpec[]

middleware_specs?

the app's middleware layers

type readonly Pick<MiddlewareSpec, "path" | "carve_outs" | "errors">[] | null
optional

returns

Map<string, RouteErrorMap>

each route's error map

resolve_route_error_map
#

http/route_errors.ts view source

(spec: RouteErrorMapSpec, middleware_specs?: readonly Pick<MiddlewareSpec, "path" | "errors" | "carve_outs">[] | null | undefined): RouteErrorMap import {resolve_route_error_map} from '@fuzdev/fuz_app/http/route_errors.js';

Resolve a route's error map: the union of the definitions derived from it (derive_route_errors, narrowed to the slots it has), those of each middleware layer that runs on it (middleware_spec_applies), in list order, and its own errors. Nothing replaces anything: a definition at a status another layer declares is one more branch there, and a repeat counts once.

spec

the route spec

middleware_specs?

the app's middleware layers, of which those that apply to the route contribute

type readonly Pick<MiddlewareSpec, "path" | "carve_outs" | "errors">[] | null
optional

returns

RouteErrorMap

the route's error map

RouteErrorMap
#

http/route_errors.ts view source

RouteErrorMap import type {RouteErrorMap} from '@fuzdev/fuz_app/http/route_errors.js';

A route's error map: every error definition the route can answer with, and the status map they group into. Built by resolve_route_error_map, and read by every reader of a route's declared errors — the surface, the DEV error check, the test helpers, error coverage, and the attack-surface suite.

defs

The definitions, in order — derived, then each applying middleware's, then the route's own — with each repeat left out (dedupe_rest_errors). Two shapes of one code at one status are both kept.

type readonly RestErrorDef<number, string, SchemaEntries>[]

readonly

schemas

The definitions grouped by status (to_error_schemas): one schema, or a union of them.

type ErrorSchemas

readonly

RouteErrorMapSpec
#

Depends on
#

Imported by
#