Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/base/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4231,7 +4231,11 @@ async fn test_drop_socket_when_http_handler_returns_an_invalid_value() {
None,
(|resp| async {
let res = resp.unwrap();
assert!(res.status().as_u16() == 502);
assert!(res.status().as_u16() == 500);
assert_eq!(
res.headers().get("x-edge-runtime-error").unwrap(),
"invalid-handler-response"
);
}),
TerminationToken::new()
);
Expand All @@ -4246,7 +4250,11 @@ async fn test_drop_socket_when_http_handler_returns_an_invalid_value() {
None,
(|resp| async {
let res = resp.unwrap();
assert!(res.status().as_u16() == 502);
assert!(res.status().as_u16() == 500);
assert_eq!(
res.headers().get("x-edge-runtime-error").unwrap(),
"invalid-handler-response"
);
}),
TerminationToken::new()
);
Expand Down
9 changes: 6 additions & 3 deletions ext/runtime/js/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ function internalServerError() {
return new Response("Internal Server Error", { status: 500 });
}

function badGatewayError() {
return new Response("Bad Gateway", { status: 502 });
function invalidHandlerResponseError() {
return new Response("Internal Server Error", {
status: 500,
headers: { "x-edge-runtime-error": "invalid-handler-response" },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

});
}

function serveHttp(conn) {
Expand Down Expand Up @@ -87,7 +90,7 @@ function serveHttp(conn) {
resp = await resp;
if (!(ObjectPrototypeIsPrototypeOf(ResponsePrototype, resp))) {
needThrow = false;
await nextRequest.respondWith(badGatewayError());
await nextRequest.respondWith(invalidHandlerResponseError());
throw new TypeError(
"First argument to 'respondWith' must be a Response or a promise resolving to a Response",
);
Expand Down
Loading