Skip to content

feat!: make HttpError data-first with one constructor form - #21

Merged
KyleJune merged 3 commits into
mainfrom
claude/project-thread-uz7ea9
Dec 4, 2026
Merged

KyleJune merged 3 commits into
mainfrom
claude/project-thread-uz7ea9

Conversation

@KyleJune

@KyleJune KyleJune commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Requested by Kyle · project thread

Closes #18. Part of the Rust port plan (udibo/oauth2#275).

Why

HttpError had four constructor overloads, name doubling as the Problem Details title, exposedMessage as the public detail, a statusText reason phrase and a class factory. A Rust crate can't share that shape. Now an error is just its RFC 9457 data, built from one options object, and a language-neutral vector file pins exactly what every input serializes to. The Rust crate (#19) will pass the same file.

Outline

-new HttpError(404, "No such user.", { exposedMessage, name, statusText, ... })
+new HttpError({ status: 404, message: "No such user.", detail, title, type, instance, extensions, headers, expose, cause })
-error.exposedMessage   error.name (title)   error.statusText   createHttpErrorClass(...)
+error.detail          error.title (name mirrors it)   (removed)   class X extends HttpError {}
+conformance/vectors/problem-details.json   serialize, parse, defaults (every status 400-599)
+conformance/README.md                      the format and the rules the cases pin

The rules stay the same: expose defaults to true for 4xx and false for 5xx, and detail is the explicit detail, else the exposed message, else the status's stock sentence.

What changed:

  • An extension named after a standard member is never serialized.
  • Empty title, type and instance count as unset.
  • Assigning name sets title.
  • HttpError.from no longer takes a foreign error's name as the title, so a Hono HTTPException(400) is titled "Bad Request", not "Error".
  • from never copies a foreign error's detail or headers. Before, any Headers or plain-object headers, including set-cookie and content-length, were relayed to the client.
  • A parsed problem's detail becomes the message, so an upstream 5xx detail stays private, as in 0.12.
  • When the body isn't Problem Details, from(Response) keeps the response's status, unexposed.
  • A problem whose own status is not an error status falls back to the response's status, then 500.
  • The 407 and 422 titles follow RFC 9110: "Proxy Authentication Required" and "Unprocessable Content".

conformance/README.md also pins the parse edge cases another language would otherwise guess at: integer-valued floats, a byte-order mark, null members, empty strings and a __proto__ member.

Verification

From typescript/, Node 26:

  • pnpm check passes.
  • pnpm test:coverage passes 107 tests at 100% statements and branches. src/conformance.test.ts runs every vector.
  • pnpm build and pnpm smoke pass, with the smoke consumer updated to the new API.
  • Two mutations, letting extensions override standard members and exposing an unexposed message, fail 10 tests, 8 of them vectors.
  • An independent review ran 19 single mutations. It found that a parsed or foreign detail leaked past expose, that setting name threw, and that several parse cases were unpinned. All three are fixed in d688201, each with a vector or test that fails without the fix.

The oauth2 update is built and passes oauth2's full suite (183 files, 6,132 tests) against this build. The udibo app is converted by a codemod (about 935 call sites, tsc -b clean apart from an unrelated oauth2 catch-up). Both land in their own PRs after this releases.

Risk

Door: one-way. This is a breaking change that releases 0.13.0 to npm and JSR (feat!, a minor version while on 0.x). The only consumers are oauth2 and the udibo app, and both are updated before they take it.

Tradeoffs

  • I kept the stock detail sentences instead of omitting detail for unexposed errors. Omitting it would make detail optional and break about 500 places in udibo that render it as a string. The vectors carry the table, so Rust copies it from there.
  • getResponse() keeps its name to limit churn.

https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS


Generated by Claude Code

An HttpError is now its RFC 9457 data (status, title, detail, type,
instance, extensions, headers, expose) built from one options object, so
the TypeScript package and the coming Rust crate can share one shape.
conformance/vectors/problem-details.json pins the response every input
produces, how a problem response parses, and every status's default title
and detail; the TypeScript suite runs the vectors.

BREAKING CHANGE: the constructor takes only an options object:
new HttpError({ status, message, ... }). exposedMessage is renamed detail
and the detail option sets it; the name option is now title. statusText and
createHttpErrorClass are removed; extend HttpError for custom errors.
HttpError.from no longer copies a foreign error's name as the title, keeps
a response's status when its body is not Problem Details, and falls back to
the response's status when a problem's own status is not an error status.

Closes #18

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS
@KyleJune KyleJune self-assigned this Dec 4, 2026
A parsed problem's detail and a foreign error's detail were sent to the
client even when the error was not exposed, so a server relaying an
upstream 5xx leaked its detail. A parsed detail is now the message, which
expose governs, and a foreign error's detail and headers are not copied.

Assigning name sets the title instead of throwing; empty title, type and
instance count as unset; a __proto__ extension serializes; a null standard
member does not make a problem. The vectors now pin these, integral-float
and byte-order-mark parsing, and use the RFC 9110 titles for 407 and 422.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS
@KyleJune
KyleJune marked this pull request as ready for review December 4, 2026 12:52
@KyleJune
KyleJune merged commit 093e25f into main Dec 4, 2026
20 checks passed
github-actions Bot pushed a commit that referenced this pull request Dec 4, 2026
## [0.13.0](0.12.1...0.13.0) (2026-12-04)

### ⚠ BREAKING CHANGES

* make HttpError data-first with one constructor form (#21)

### Features

* make HttpError data-first with one constructor form ([#21](#21)) ([093e25f](093e25f)), closes [udibo/oauth2#275](udibo/oauth2#275) [#19](#19)
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 0.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make HttpError data-first with one constructor form

2 participants