diff options
author | Jesse Luehrs <doy@tozt.net> | 2023-07-18 02:03:27 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2023-07-18 02:03:27 -0400 |
commit | 9fb13ee0ca17c6bfcb50c21e0dbffc93813e2d9d (patch) | |
tree | 18e0591f6e735c7d1d507a9c09971902d751dfe4 | |
parent | d28750a980985101799af6947bc3274dca026ad9 (diff) | |
download | rbw-9fb13ee0ca17c6bfcb50c21e0dbffc93813e2d9d.tar.gz rbw-9fb13ee0ca17c6bfcb50c21e0dbffc93813e2d9d.zip |
improve error reporting when login or register fail
-rw-r--r-- | src/api.rs | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -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 }) + } + } } } |