fix(ext/runtime): return 500 instead of 502 for invalid handler response - #720
Open
davidbirdsong wants to merge 1 commit into
Open
fix(ext/runtime): return 500 instead of 502 for invalid handler response#720davidbirdsong wants to merge 1 commit into
davidbirdsong wants to merge 1 commit into
Conversation
Author
|
This change is part of the following stack: Change managed by git-spice. |
A handler resolving to a non-Response value is a contract violation on our side, not a bad response from an upstream gateway target. Tag it with x-edge-runtime-error so it's distinguishable from other 500s and from the unrelated upsteram 502s.
davidbirdsong
force-pushed
the
fix/ext-runtime-invalid-response-status
branch
from
August 21, 2026 21:31
aace5d1 to
4d77e3d
Compare
kallebysantos
approved these changes
Aug 24, 2026
kallebysantos
requested changes
Aug 24, 2026
| function invalidHandlerResponseError() { | ||
| return new Response("Internal Server Error", { | ||
| status: 500, | ||
| headers: { "x-edge-runtime-error": "invalid-handler-response" }, |
Member
There was a problem hiding this comment.
You're introducing a new header,
I believe we should use the sb-error-code or discuss to find an better edge-runtime error pattern
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 kind of change does this PR introduce?
Bug fix.
What is the current behavior?
When a
serve()handler (main worker, event worker, or a user function) resolves with something that isn't aResponseobject,ext/runtime/js/http.jsfalls back to a bare502 Bad Gatewaywith a generic"Bad Gateway"body.502 implies edge-runtime received an invalid response from an upstream/gateway target. That's not what's happening here: the "handler" runs in-process, and the violation is edge-runtime's own contract (a handler must resolve to a
Response) not being honored. Framing it as a gateway error also makes this failure indistinguishable from unrelated, real gateway-level 502s, which complicates 502 triage.What is the new behavior?
500 Internal Server Errorinstead of502 Bad Gateway, which more accurately reflects that the fault is internal, not upstream.x-edge-runtime-error: invalid-handler-response, so this specific failure mode can be distinguished from other 500s and from unrelated 502s in logs/metrics without relying on status code alone.badGatewayError()is renamed toinvalidHandlerResponseError()to match what it actually represents.Additional context
No functional change to the "handler threw an exception" path (
internalServerError(), still 500, unchanged) — this only affects the "handler resolved to a non-Response value" path.