Serialization and API errors
View as MarkdownIdentity
Section titled “Identity”Temporal helpers from @sapporta/shared/temporal, error schema from
@sapporta/shared/contracts, validation normalization from
@sapporta/shared/validation, and ApiError from @sapporta/shared/client.
Contract
Section titled “Contract”- Calendar dates use ISO
YYYY-MM-DDstrings and parse asTemporal.PlainDateat typed boundaries. - Timestamps use canonical ISO instants and parse as
Temporal.Instantwhere the schema declares them. - HTTP errors carry a structured body declared by the owning contract or infrastructure boundary.
ApiErrorrepresents a non-2xx HTTP response that reaches client unwrapping. Its numericstatusis preserved and itsbodyisunknown.- Network failures remain transport failures rather than fabricated HTTP
statuses. Response-schema validation failures also pass through as validation
failures instead of becoming
ApiError. - Validation failures and domain failures remain separate declared response branches.
FieldIssuerepresents one presentation-neutral{ field, message }validation issue.fieldIssuesFromZodError()preserves nested paths with dot notation and maps pathless issues toform.apiProblemFromBody()accepts only a valid Sapporta error body. It returns{ summary, code?, fieldIssues }, recognizes directfieldvalues and Zodpatharrays, and ignores unrecognized details. Invalid bodies returnundefined.apiProblemFromBody()is suitable for display normalization. Its optional genericcodeis not exhaustive proof for a feature-specific recovery branch.- When recovery changes behavior, parse
ApiError.bodywith the exported strict feature schema and require the expected status/code pair. - Expected service/store failures use one HTTP-aware typed error family carrying status and payload, plus one exhaustive route-edge adapter. Errors outside that family escape to the application’s central path.
- Malformed bodies, status/code mismatches, transport failures, response-validation failures, and unexpected errors do not enter a declared recovery branch.
- Protected feature contracts list their feature-owned failures. The shared
authentication middleware owns common
401and403envelopes outside each feature contract.