feat: typed error responses with $error<T> and status-keyed response maps#2
Draft
Copilot wants to merge 2 commits into
Draft
feat: typed error responses with $error<T> and status-keyed response maps#2Copilot wants to merge 2 commits into
$error<T> and status-keyed response maps#2Copilot wants to merge 2 commits into
Conversation
Agent-Logs-Url: https://github.com/alloc/rouzer/sessions/ad2874c8-97ca-4ce2-8013-e7bf328459c6 Co-authored-by: aleclarson <1925840+aleclarson@users.noreply.github.com>
- Add $error<T>() marker function for declaring error response types - Support status-keyed response maps in route schemas - Add ctx.error(status, body) to server handler context - Client resolves declared errors as [error, null, status] tuples - Undeclared statuses still reject the promise - Add runtime and type-level tests Agent-Logs-Url: https://github.com/alloc/rouzer/sessions/ad2874c8-97ca-4ce2-8013-e7bf328459c6 Co-authored-by: aleclarson <1925840+aleclarson@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
aleclarson
May 23, 2026 13:32
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds declared error responses as part of the route contract. Declared HTTP errors resolve as typed tuples on the client instead of rejecting, while unexpected/undeclared failures still reject.
Changes
$error<T>()marker — new compile-time marker analogous to$type<T>(), distinguishes error branches in a response mapresponsefield now accepts{ [status]: $type<T>() | $error<T>() }in addition to the existing single-marker formctx.error(status, body)— server handler helper typed to only accept statuses declared with$error<T>(); returns aResponsewith the given status$error<T>entries, the client resolves all declared statuses as[error, result, status]discriminated tuplesInferRouteResponseproduces the tuple union;InferRouteHandlerResultextracts success types;InferResponseMapErrorstypes the error helperExample
Backward compatibility
Existing
response: $type<T>()andresponse: ndjson.$type<T>()routes are unchanged — no tuple wrapping, no breaking type changes. The response map form is purely additive.