1
0
Fork 0
mirror of https://git.42l.fr/neil/sncf.git synced 2024-05-11 02:06:34 +02:00

more debug info when NC returns bad status code

This commit is contained in:
bleh 2020-08-22 12:05:23 +02:00
parent 5014e79b06
commit be19e37cb7

View file

@ -77,6 +77,12 @@ pub async fn create_account(
// only 200 http status code is allowed // only 200 http status code is allowed
if register_query.status() != 200 { if register_query.status() != 200 {
eprintln!("error_createaccount_status: {}", register_query.status()); 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")); 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| { let post_body = login_get.body().await.map_err(|e| {
eprintln!("error_login_get_body: {}", e); eprintln!("error_login_get_body: {}", e);
crash(get_lang(&req), "error_login_get_body") crash(get_lang(&req), "error_login_get_body")
})?; })?;
let post_body_str = String::from_utf8_lossy(&post_body); let post_body_str = String::from_utf8_lossy(&post_body);
// save requesttoken (CSRF) for POST // save requesttoken (CSRF) for POST
@ -162,12 +168,12 @@ pub async fn login(
eprintln!("error_login_regex (no capture)"); eprintln!("error_login_regex (no capture)");
crash(get_lang(&req), "error_login_regex") crash(get_lang(&req), "error_login_regex")
})? })?
.name("token") .name("token")
.ok_or_else(|| { .ok_or_else(|| {
eprintln!("error_login_regex (no capture named token)"); eprintln!("error_login_regex (no capture named token)");
crash(get_lang(&req), "error_login_regex") crash(get_lang(&req), "error_login_regex")
})? })?
.as_str(); .as_str();
// 2. POST /login // 2. POST /login
let mut login_post = client let mut login_post = client
@ -186,10 +192,10 @@ pub async fn login(
timezone_offset: "2", timezone_offset: "2",
requesttoken, requesttoken,
}) })
.await.map_err(|e| { .await.map_err(|e| {
eprintln!("error_login_post: {}", e); eprintln!("error_login_post: {}", e);
crash(get_lang(&req), "error_login_post") crash(get_lang(&req), "error_login_post")
})?; })?;
// 3. set the same cookies in the user's browser // 3. set the same cookies in the user's browser
let mut user_response = HttpResponse::SeeOther(); let mut user_response = HttpResponse::SeeOther();