jsonError — emit a uniform { error: string } JSON body with the right
HTTP status. Single shape across the API surface.
mapErrorToResponse + the friendly* helpers — turn each error class
into one actionable English sentence. Technical detail (stack, upstream
codes, raw model output) stays in console.warn for wrangler tail.
Pattern matching is by status code first, then by message keyword. Keeping
this layer separate from the handler keeps the handler readable and makes
the translation rules unit-testable in isolation.
Errors layer — translate internal domain/adapter errors to user-safe HTTP responses.
Two responsibilities:
jsonError— emit a uniform{ error: string }JSON body with the right HTTP status. Single shape across the API surface.mapErrorToResponse+ thefriendly*helpers — turn each error class into one actionable English sentence. Technical detail (stack, upstream codes, raw model output) stays inconsole.warnforwrangler tail.Pattern matching is by status code first, then by message keyword. Keeping this layer separate from the handler keeps the handler readable and makes the translation rules unit-testable in isolation.