fix(next)!: stitchErrorResponse returns Response | undefined so it composes#475
Open
rejifald wants to merge 1 commit into
Open
fix(next)!: stitchErrorResponse returns Response | undefined so it composes#475rejifald wants to merge 1 commit into
rejifald wants to merge 1 commit into
Conversation
…composes
`stitchErrorResponse(err)` mapped *any* thrown value to a `Response` (a `StitchError` to
502, everything else to 500), so a caller couldn't tell "handled" from "not mine": the
only way to rethrow a non-stitch error was to pre-guard with `isStitchError`, and the
internal 500 branch silently swallowed unrelated bugs into an HTTP response.
It now returns `undefined` for a non-`StitchError`, so the whole map-or-rethrow collapses
to one branch:
const mapped = stitchErrorResponse(err);
if (mapped) return mapped;
throw err;
This is the contract `@stitchapi/elysia`'s `stitchErrorResponse` already ships on `main`
(`stitchErrorResponse(err) ?? new Response(...)`) — this aligns `@stitchapi/next` with it.
Updates the next tests, README, and integration doc to the composition pattern (the now
built-in check makes the doc snippets' `isStitchError` pre-guard redundant).
BREAKING: `stitchErrorResponse(nonStitchError)` was a `500` `Response`; it is now
`undefined`. Pre-GA. Carved out of the #470 contract-freeze sweep so this contract change
lands and is reviewed on its own.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
@stitchapi/next'sstitchErrorResponse(err)mapped any thrown value to aResponse(a
StitchError→502, everything else →500). That made "I handled it" and "not myerror" indistinguishable at the call site: to rethrow a non-stitch error you had to
pre-guard with
isStitchError, and the internal500branch silently swallowedunrelated bugs into an HTTP response.
It now returns
undefinedfor a non-StitchError, so map-or-rethrow collapses to onebranch:
This is the contract
@stitchapi/elysia'sstitchErrorResponsealready ships onmain(
stitchErrorResponse(err) ?? new Response(...)); this aligns@stitchapi/nextwith it.stitchErrorResponse(nonStitchError)was a500Response; it is nowundefined. Pre-GA,no deprecation. Callers that relied on the catch-all 500 should pass an explicit fallback
(
stitchErrorResponse(err) ?? Response.json(…, { status: 500 })).Changed
src/index.ts— guardif (!isStitchError(err)) return undefined;, return typeResponse | undefined, drop the now-dead non-stitch500branch.test/next.spec.ts— flip the non-stitch case totoBeUndefined(); narrow theStitchError cases through a small
mustRespondhelper.README.md+integrations/next.mdx— composition pattern; drop the now-redundantisStitchErrorpre-guard from the snippet.Context
Carved out of the #470 contract-freeze sweep so this contract change lands and is reviewed
on its own. (In #470 it also picks up an
ErrorResponseOptions→StitchErrorOptionsrenameand a
BAD_GATEWAYconst — omitted here to keep the diff to the behavior change.)Verification
pnpm --filter @stitchapi/next test(18 pass) +check:typesclean; full pre-push suitegreen (incl.
build-docstwoslash-compiling the updatednext.mdx).🤖 Generated with Claude Code