acme: move Problem extraction into associated function
This commit is contained in:
parent
827c3baa6a
commit
3e64360c59
|
@ -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,
|
||||
|
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue