feat(paheko): print error details

This commit is contained in:
Matthieu Bessat 2024-01-19 13:04:11 +01:00
parent bbea78cea3
commit 978c00c1dc

View file

@ -285,6 +285,7 @@ impl AuthentifiedClient {
.json(&payload) .json(&payload)
.send().await?; .send().await?;
if res.status() != 200 { if res.status() != 200 {
self.show_paheko_err(res).await;
return Err(APIClientError::InvalidStatusCode.into()); return Err(APIClientError::InvalidStatusCode.into());
} }
res.json().await.context("Sql query") res.json().await.context("Sql query")
@ -337,6 +338,7 @@ impl AuthentifiedClient {
.get(path) .get(path)
.send().await?; .send().await?;
if res.status() != 200 { if res.status() != 200 {
self.show_paheko_err(res).await;
return Err(APIClientError::InvalidStatusCode.into()); return Err(APIClientError::InvalidStatusCode.into());
} }
res.json().await.context("Get accounting years") res.json().await.context("Get accounting years")
@ -428,6 +430,7 @@ impl AuthentifiedClient {
.send().await?; .send().await?;
if res.status() != 200 { if res.status() != 200 {
self.show_paheko_err(res).await;
return Err(APIClientError::InvalidStatusCode.into()); return Err(APIClientError::InvalidStatusCode.into());
} }
Ok( Ok(
@ -476,6 +479,7 @@ impl AuthentifiedClient {
.send().await?; .send().await?;
if res.status() != 200 { if res.status() != 200 {
self.show_paheko_err(res).await;
return Err(APIClientError::InvalidStatusCode.into()); return Err(APIClientError::InvalidStatusCode.into());
} }
Ok(UserServiceRegistration { Ok(UserServiceRegistration {
@ -514,8 +518,13 @@ impl AuthentifiedClient {
.send().await?; .send().await?;
if res.status() != 200 { if res.status() != 200 {
self.show_paheko_err(res).await;
return Err(APIClientError::InvalidStatusCode.into()); return Err(APIClientError::InvalidStatusCode.into());
} }
Ok(()) Ok(())
} }
async fn show_paheko_err(&self, err_response: reqwest::Response) -> () {
eprintln!("Paheko Error Details: {:?} {:?}", err_response.status(), err_response.text().await.unwrap())
}
} }