errormodel

package
v0.0.0-...-10ede12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package errormodel installs the request-validation error model the service answers with.

Huma's default model echoes the rejected value back to the caller in errors[].value. For an ordinary field that is a debugging aid. For a credential it is a disclosure: a refused API key, password or one-time code travels back out in the response body and from there into proxy and access logs, browser history, error-reporting clients, and any support ticket the body is pasted into.

Install keeps the refusal useful — message and location still name the field and say what was wrong with it — and drops only the value, on three structural grounds:

  • The value is a composite (object or array). Huma reports a missing required property against the enclosing object, so the echoed value is the whole request body with every sibling field in it. There is no way to know none of them is a secret, and the message already names the property that was missing.
  • The location is `body` itself. That is the body-parse failure path, where the echoed value is the raw request payload.
  • The field must not be reflected: its schema declares it write-only, or the shared log redactor refuses to print a JSON member under that name.

A string value that survives all three is still passed through logutil.Redact, so a token pasted into an ordinary field is scrubbed by the same prefix scanner that guards the logs.

auth-api carries the same package. Neither service can import the other's internal packages, so the policy is stated once per service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AIFailure

func AIFailure(err error) (*apierr.Spec, string)

AIFailure maps an error from the AI layer to the catalog code every transport answers with, plus the upstream Retry-After value when the provider supplied one ("" otherwise).

It is the only mapping for this failure family: REST handlers pass the pair straight to handlerutil.HTTPErrWithRetryAfter, and MCP tools wrap the spec with apierrors.Wrap, so the same failure reads the same on every surface. Anything unrecognised is reported as an unreachable provider.

func Install

func Install()

Install replaces huma.NewError with a wrapper that sanitises the echoed values of every error detail Huma produces, including the validation failures raised before a handler ever runs, and gives those failures their catalog code.

huma.NewError is process-global and huma.NewErrorWithContext delegates to it, so one call covers every sub-API the router mounts. Repeat calls are no-ops: wrapping the wrapper would work but would grow a chain per router built, and the test harness builds many.

func LearnWriteOnlyFields

func LearnWriteOnlyFields(apis []huma.API)

LearnWriteOnlyFields records the JSON member names that the given APIs' schemas declare write-only, so a validation failure on one of them does not echo the value back.

writeOnly is the OpenAPI statement that a member is accepted in a request and never returned in a response. A value that must not appear in a success response must not appear in an error response either, so the tag on the DTO is what decides — a field gains the protection by declaring what it is, not by being added to a list here.

Call this after every operation has been registered: Huma populates the schema registry lazily as it registers them.

func PageGenerationFailure

func PageGenerationFailure(err error) (*apierr.Spec, string)

PageGenerationFailure is AIFailure for page generation, the answer REST and MCP both give. The catalog defines a page-specific code for an unreachable provider; every other failure keeps its shared code.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL