From db77699d9201c3556585d10dfd11e6d749651890 Mon Sep 17 00:00:00 2001 From: WofWca Date: Sun, 20 Apr 2025 23:30:32 +0400 Subject: [PATCH] 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. --- src/net/http.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/net/http.rs b/src/net/http.rs index e863e8f992..c50621196e 100644 --- a/src/net/http.rs +++ b/src/net/http.rs @@ -261,6 +261,18 @@ async fn fetch_url(context: &Context, original_url: &str) -> Result { 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")