From be19e37cb785a2bcd4cfa8848ac934b32890f272 Mon Sep 17 00:00:00 2001 From: bleh Date: Sat, 22 Aug 2020 12:05:23 +0200 Subject: [PATCH] more debug info when NC returns bad status code --- src/account.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/account.rs b/src/account.rs index 1a6dcd7..a130b60 100644 --- a/src/account.rs +++ b/src/account.rs @@ -77,6 +77,12 @@ pub async fn create_account( // only 200 http status code is allowed if register_query.status() != 200 { eprintln!("error_createaccount_status: {}", register_query.status()); + // + extract response body for debugging purposes + let response_body = register_query.body().await.map_err(|e| { + eprintln!("error_createaccount_post_body: {}", e); + crash(lang.clone(), "error_createaccount_post_body") + })?; + debug(&format!("Body: {:#?}", response_body)); return Err(crash(lang.clone(), "error_createaccount_status")); } @@ -150,9 +156,9 @@ pub async fn login( } let post_body = login_get.body().await.map_err(|e| { - eprintln!("error_login_get_body: {}", e); - crash(get_lang(&req), "error_login_get_body") - })?; + eprintln!("error_login_get_body: {}", e); + crash(get_lang(&req), "error_login_get_body") + })?; let post_body_str = String::from_utf8_lossy(&post_body); // save requesttoken (CSRF) for POST @@ -162,12 +168,12 @@ pub async fn login( eprintln!("error_login_regex (no capture)"); crash(get_lang(&req), "error_login_regex") })? - .name("token") + .name("token") .ok_or_else(|| { eprintln!("error_login_regex (no capture named token)"); crash(get_lang(&req), "error_login_regex") })? - .as_str(); + .as_str(); // 2. POST /login let mut login_post = client @@ -186,10 +192,10 @@ pub async fn login( timezone_offset: "2", requesttoken, }) - .await.map_err(|e| { - eprintln!("error_login_post: {}", e); - crash(get_lang(&req), "error_login_post") - })?; + .await.map_err(|e| { + eprintln!("error_login_post: {}", e); + crash(get_lang(&req), "error_login_post") + })?; // 3. set the same cookies in the user's browser let mut user_response = HttpResponse::SeeOther();