[yew-devel] [PATCH yew-comp 1/3] http client: include canonical http error with status code

Dominik Csapak d.csapak at proxmox.com
Wed Jan 8 14:23:05 CET 2025


e.g. when receiving a 401 error, this will change from

'HTTP status 401' to
'HTTP status 401 Unauthorized'

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/http_client_wasm.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/http_client_wasm.rs b/src/http_client_wasm.rs
index 7f02164..3e5b187 100644
--- a/src/http_client_wasm.rs
+++ b/src/http_client_wasm.rs
@@ -205,7 +205,8 @@ impl HttpClientWasm {
             web_sys_response_to_http_api_response(self.fetch_request(request, None).await?).await?;
 
         if !(response.status >= 200 && response.status < 300) {
-            bail!("HTTP status {}", response.status);
+            let status = http::StatusCode::from_u16(response.status)?;
+            bail!("HTTP status {status}");
         }
 
         let text = String::from_utf8(response.body)?;
-- 
2.39.5





More information about the yew-devel mailing list