diff options
author | Luca Casonato <hello@lcas.dev> | 2024-09-18 21:14:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-18 21:14:40 +0200 |
commit | 7a41a939972b701e96cb70cbf0516595fefcae02 (patch) | |
tree | ad05a7c97c9eec410c5f853f97b11c67e25672b5 /tests/unit | |
parent | ab1e391e1d700a68964e899963670e903f498cdf (diff) |
fix(ext/http): gracefully handle Response.error responses (#25712)
Fixes #14371
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/serve_test.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index c1e217a11..d417d8d26 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -678,6 +678,40 @@ Deno.test( }, ); +Deno.test( + { permissions: { net: true } }, + async function httpServerReturnErrorResponse() { + const ac = new AbortController(); + const { promise, resolve } = Promise.withResolvers<void>(); + let hadError = false; + const server = Deno.serve({ + handler: () => { + return Response.error(); + }, + port: servePort, + signal: ac.signal, + onListen: onListen(resolve), + onError: () => { + hadError = true; + return new Response("Internal Server Error", { status: 500 }); + }, + }); + + await promise; + + const resp = await fetch(`http://127.0.0.1:${servePort}/`, { + headers: { "connection": "close" }, + }); + assertEquals(resp.status, 500); + const text = await resp.text(); + assertEquals(text, "Internal Server Error"); + assert(hadError); + + ac.abort(); + await server.finished; + }, +); + Deno.test({ permissions: { net: true } }, async function httpServerOverload1() { const ac = new AbortController(); const deferred = Promise.withResolvers<void>(); |