acme: move Problem extraction into associated function

This commit is contained in:
Dirkjan Ochtman 2022-05-10 14:38:33 +02:00 committed by Dirkjan Ochtman
parent 827c3baa6a
commit 3e64360c59
2 changed files with 7 additions and 7 deletions

View File

@ -113,11 +113,7 @@ impl Account {
.and_then(|hv| hv.to_str().ok())
.map(|s| s.to_owned());
let status = rsp.status();
if status.is_client_error() || status.is_server_error() {
return Err(rsp.json::<Problem>().await?.into());
}
Problem::from_response(rsp).await?;
Ok(Self {
inner: Arc::new(AccountInner {
client,

View File

@ -49,10 +49,14 @@ pub struct Problem {
impl Problem {
pub(crate) async fn check<T: DeserializeOwned>(rsp: Response) -> Result<T, Error> {
Ok(Self::from_response(rsp).await?.json().await?)
}
pub(crate) async fn from_response(rsp: Response) -> Result<Response, Error> {
let status = rsp.status();
match status.is_client_error() || status.is_server_error() {
false => Ok(rsp.json().await?),
true => Err(rsp.json::<Self>().await?.into()),
false => Ok(rsp),
true => Err(rsp.json::<Problem>().await?.into()),
}
}
}