From 9fb13ee0ca17c6bfcb50c21e0dbffc93813e2d9d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 18 Jul 2023 02:03:27 -0400 Subject: improve error reporting when login or register fail --- src/api.rs | 28 ++++++++++++++++++++++++++-- 1 file 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 }) + } + } } } -- cgit v1.2.3-54-g00ecf