The 'Ok::<_, Self::Error>(res)' type annotation was from a time where
we could not use async, and had a combinator here which needed
explicity type information. We switched over to async in commit
91e4587343c155cd3aa9274bd2c736dcc1ccf977 and, as the type annotation
is already included in the Future type, we can safely drop it.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
let config = Arc::clone(&self.api_config);
let peer = self.peer;
async move {
let config = Arc::clone(&self.api_config);
let peer = self.peer;
async move {
- match handle_request(config, req).await {
- Ok(res) => {
- log_response(&peer, method, &path, &res);
- Ok::<_, Self::Error>(res)
- }
+ let response = match handle_request(config, req).await {
+ Ok(response) => response,
- if let Some(apierr) = err.downcast_ref::<HttpError>() {
- let mut resp = Response::new(Body::from(apierr.message.clone()));
- *resp.status_mut() = apierr.code;
- log_response(&peer, method, &path, &resp);
- Ok(resp)
- } else {
- let mut resp = Response::new(Body::from(err.to_string()));
- *resp.status_mut() = StatusCode::BAD_REQUEST;
- log_response(&peer, method, &path, &resp);
- Ok(resp)
- }
+ let (err, code) = match err.downcast_ref::<HttpError>() {
+ Some(apierr) => (apierr.message.clone(), apierr.code),
+ _ => (err.to_string(), StatusCode::BAD_REQUEST),
+ };
+ Response::builder().status(code).body(err.into())?
+ };
+ log_response(&peer, method, &path, &response);
+ Ok(response)