Skip to content

Commit db77699

Browse files
committed
fix: fetch_url: return err on non 2xx reponses
The main reason for this change is the app picker that Delta Chat clients use, which utilizes the `fetch_url` function. Sometimes we get an error from the server, but we have no way to figure out that it's an error, other than inspecting the body, which we don't (and shouldn't) do. This results in us attempting to send webxdc apps that are not even valid .zip files. Another, arguably even worse thing is that we also put the error responses to the cache, so it's not easy to recover from such an error. So, let's just return an error if the response code is not a successful response code.
1 parent 9d3450f commit db77699

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/net/http.rs

+12
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ async fn fetch_url(context: &Context, original_url: &str) -> Result<Response> {
261261
continue;
262262
}
263263

264+
if !response.status().is_success() {
265+
return Err(anyhow!(
266+
"The server returned a non-successful response code: {}{}",
267+
response.status().as_u16(),
268+
response
269+
.status()
270+
.canonical_reason()
271+
.map(|s| format!(" {s}"))
272+
.unwrap_or("".to_string())
273+
));
274+
}
275+
264276
let content_type = response
265277
.headers()
266278
.get("content-type")

0 commit comments

Comments
 (0)