debug-request-quth

This commit is contained in:
Untone 2023-12-13 18:13:19 +03:00
parent d15633af0f
commit e832e57715

View File

@ -26,21 +26,29 @@ pub async fn get_auth_id(token: &str) -> Result<i32, Box<dyn Error>> {
} }
} }
}); });
println!("GraphQL Request: {:?}", gql);
let client = HTTPClient::new(); let client = HTTPClient::new();
let response = client let response = client
.post(&auth_api_base) .post(&auth_api_base)
.headers(headers) .headers(headers)
.json(&gql) .json(&gql)
.send() .send()
.await?; .await;
let response = match response {
Ok(res) => res,
Err(err) => {
println!("Error sending request: {:?}", err);
return Err(Box::new(err));
}
};
if response.status().is_success() { if response.status().is_success() {
let r: HashMap<String, serde_json::Value> = response.json().await?; let r: HashMap<String, serde_json::Value> = response.json().await?;
let user_id = r let user_id = r
.get("data") .get("data")
.and_then(|data| data.get("validate_jwt_token")) .and_then(|data| data.get("validate_jwt_token"))
.and_then(|query| query.get("clams")) .and_then(|query| query.get("claims"))
.and_then(|claims| claims.get("sub")) .and_then(|claims| claims.get("sub"))
.and_then(|id| id.as_i64()); .and_then(|id| id.as_i64());
@ -58,7 +66,6 @@ pub async fn get_auth_id(token: &str) -> Result<i32, Box<dyn Error>> {
} }
} }
} else { } else {
println!("Request failed with status: {}", response.status());
Err(Box::new(std::io::Error::new( Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other, std::io::ErrorKind::Other,
format!("Request failed with status: {}", response.status()), format!("Request failed with status: {}", response.status()),