Skip to content

Commit 3aed4a6

Browse files
authored
Expose reqwest's inner error in the fetch function (#424)
* Expose reqwest's inner error in the `fetch` function We were converting the `reqwest::Error` type directly to `span::Error` and the rendering chain stopped at that. This ignored the inner (source) error which contained the most useful information to figure out what went wrong. This gets us from: Error: error: failed to fetch: error: error decoding response body to: Error: error: failed to fetch: error: error decoding response body: missing field `discord` at line 16049 column 1 * Generate a spanned::Error directly from the inner JSON error The code is shorter and less hacky. The end-user message looks much better too. * Use `to_string()` instead of `format!` * Move the question mark out of `Ok(json_response?)`
1 parent 62d06a3 commit 3aed4a6

File tree

1 file changed

+9
-1
lines changed
  • crates/rust-project-goals/src

1 file changed

+9
-1
lines changed

crates/rust-project-goals/src/team.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ where
122122
// dropped.
123123
in_thread(|| {
124124
let url = format!("{}/{}", v1::BASE_URL, path);
125-
Ok(reqwest::blocking::get(&url)?.json()?)
125+
let json_response = reqwest::blocking::get(&url)?.json().map_err(|e| {
126+
use std::error::Error;
127+
128+
e.source()
129+
.map(|json_error| spanned::Error::str(json_error.to_string()))
130+
.unwrap_or(e.into())
131+
})?;
132+
133+
Ok(json_response)
126134
})
127135
}

0 commit comments

Comments
 (0)