aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-07-18 02:03:27 -0400
committerJesse Luehrs <doy@tozt.net>2023-07-18 02:03:27 -0400
commit9fb13ee0ca17c6bfcb50c21e0dbffc93813e2d9d (patch)
tree18e0591f6e735c7d1d507a9c09971902d751dfe4
parentd28750a980985101799af6947bc3274dca026ad9 (diff)
downloadrbw-9fb13ee0ca17c6bfcb50c21e0dbffc93813e2d9d.tar.gz
rbw-9fb13ee0ca17c6bfcb50c21e0dbffc93813e2d9d.zip
improve error reporting when login or register fail
-rw-r--r--src/api.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/api.rs b/src/api.rs
index fb4fc42..bee0606 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -784,7 +784,19 @@ impl Client {
Ok(())
} else {
let code = res.status().as_u16();
- Err(classify_login_error(&res.json_with_path().await?, code))
+ match res.text().await {
+ Ok(body) => match body.clone().json_with_path() {
+ Ok(json) => Err(classify_login_error(&json, code)),
+ Err(e) => {
+ log::warn!("{e}: {body}");
+ Err(Error::RequestFailed { status: code })
+ }
+ },
+ Err(e) => {
+ log::warn!("failed to read response body: {e}");
+ Err(Error::RequestFailed { status: code })
+ }
+ }
}
}
@@ -832,7 +844,19 @@ impl Client {
))
} else {
let code = res.status().as_u16();
- Err(classify_login_error(&res.json_with_path().await?, code))
+ match res.text().await {
+ Ok(body) => match body.clone().json_with_path() {
+ Ok(json) => Err(classify_login_error(&json, code)),
+ Err(e) => {
+ log::warn!("{e}: {body}");
+ Err(Error::RequestFailed { status: code })
+ }
+ },
+ Err(e) => {
+ log::warn!("failed to read response body: {e}");
+ Err(Error::RequestFailed { status: code })
+ }
+ }
}
}