Skip to content

Commit

Permalink
fix(ext/fetch): include URL and error details on fetch failures
Browse files Browse the repository at this point in the history
  • Loading branch information
magurotuna committed Aug 6, 2024
1 parent c0e9512 commit 47dbb42
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ deno_core.workspace = true
deno_permissions.workspace = true
deno_tls.workspace = true
dyn-clone = "1"
error_reporter = "1"
http.workspace = true
http-body-util.workspace = true
hyper.workspace = true
Expand Down
10 changes: 9 additions & 1 deletion ext/fetch/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,15 @@ impl Client {
req.headers_mut().insert(PROXY_AUTHORIZATION, auth.clone());
}

let resp = self.inner.oneshot(req).await?;
let url = req.uri().to_string();

let resp = self.inner.oneshot(req).await.map_err(|e| {
anyhow!(
"error sending request for url ({url}): {}",
// NOTE: we can use `std::error::Report` instead once it's stabilized.
error_reporter::Report::new(e)
)
})?;
Ok(resp.map(|b| b.map_err(|e| anyhow!(e)).boxed()))
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/fetch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2060,3 +2060,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: failed to lookup address information:",
);
},
);

0 comments on commit 47dbb42

Please sign in to comment.