diff --git a/crates/base/tests/integration_tests.rs b/crates/base/tests/integration_tests.rs index 1e76dfbab..45f63e28c 100644 --- a/crates/base/tests/integration_tests.rs +++ b/crates/base/tests/integration_tests.rs @@ -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() ); @@ -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() ); diff --git a/ext/runtime/js/http.js b/ext/runtime/js/http.js index 5c19aa2f2..5fc1923f9 100644 --- a/ext/runtime/js/http.js +++ b/ext/runtime/js/http.js @@ -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" }, + }); } function serveHttp(conn) { @@ -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", );