mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 02:46:29 +03:00
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.
This commit is contained in:
@@ -261,6 +261,18 @@ async fn fetch_url(context: &Context, original_url: &str) -> Result<Response> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(anyhow!(
|
||||
"The server returned a non-successful response code: {}{}",
|
||||
response.status().as_u16(),
|
||||
response
|
||||
.status()
|
||||
.canonical_reason()
|
||||
.map(|s| format!(" {s}"))
|
||||
.unwrap_or("".to_string())
|
||||
));
|
||||
}
|
||||
|
||||
let content_type = response
|
||||
.headers()
|
||||
.get("content-type")
|
||||
|
||||
Reference in New Issue
Block a user