summaryrefslogtreecommitdiff
path: root/tests/unit/fetch_test.ts
diff options
context:
space:
mode:
authorYusuke Tanaka <yusuktan@maguro.dev>2024-08-08 15:18:33 +0900
committerGitHub <noreply@github.com>2024-08-07 23:18:33 -0700
commit4e4c96bf66111c6e8ba976ed24594edf7abfcbfb (patch)
tree3fc2f08999df8726bd53578443556c4a0fec42b7 /tests/unit/fetch_test.ts
parent9d6da1036d80a29862f6bdfb51e6f51eee235c35 (diff)
fix(ext/fetch): include URL and error details on fetch failures (#24910)
This commit improves error messages that `fetch` generates on failure. Fixes #24835
Diffstat (limited to 'tests/unit/fetch_test.ts')
-rw-r--r--tests/unit/fetch_test.ts26
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts
index 09cbb5cd2..5ebc0c86f 100644
--- a/tests/unit/fetch_test.ts
+++ b/tests/unit/fetch_test.ts
@@ -1976,14 +1976,17 @@ Deno.test(
},
});
- const err = await assertRejects(() =>
- fetch(`http://localhost:${listenPort}/`, {
- body: stream,
- method: "POST",
- })
+ const url = `http://localhost:${listenPort}/`;
+ const err = await assertRejects(
+ () =>
+ fetch(url, {
+ body: stream,
+ method: "POST",
+ }),
+ TypeError,
+ `error sending request for url (${url}): client error (SendRequest): error from user's Body stream`,
);
- assert(err instanceof TypeError, `err was not a TypeError ${err}`);
assert(err.cause, `err.cause was null ${err}`);
assert(
err.cause instanceof Error,
@@ -2060,3 +2063,14 @@ Deno.test("URL authority is used as 'Authorization' header", async () => {
await server.finished;
assertEquals(authHeader, "Basic ZGVubzpsYW5k");
});
+
+Deno.test(
+ { permissions: { net: true } },
+ async function errorMessageIncludesUrlAndDetails() {
+ await assertRejects(
+ () => fetch("http://example.invalid"),
+ TypeError,
+ "error sending request for url (http://example.invalid/): client error (Connect): dns error: ",
+ );
+ },
+);