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())
|
.and_then(|hv| hv.to_str().ok())
|
||||||
.map(|s| s.to_owned());
|
.map(|s| s.to_owned());
|
||||||
|
|
||||||
let status = rsp.status();
|
Problem::from_response(rsp).await?;
|
||||||
if status.is_client_error() || status.is_server_error() {
|
|
||||||
return Err(rsp.json::<Problem>().await?.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
inner: Arc::new(AccountInner {
|
inner: Arc::new(AccountInner {
|
||||||
client,
|
client,
|
||||||
|
|
|
@ -49,10 +49,14 @@ pub struct Problem {
|
||||||
|
|
||||||
impl Problem {
|
impl Problem {
|
||||||
pub(crate) async fn check<T: DeserializeOwned>(rsp: Response) -> Result<T, Error> {
|
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();
|
let status = rsp.status();
|
||||||
match status.is_client_error() || status.is_server_error() {
|
match status.is_client_error() || status.is_server_error() {
|
||||||
false => Ok(rsp.json().await?),
|
false => Ok(rsp),
|
||||||
true => Err(rsp.json::<Self>().await?.into()),
|
true => Err(rsp.json::<Problem>().await?.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue