1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-07-01 08:45:10 +02:00

refined error model (#2253)

This commit is contained in:
Rob Ede
2021-06-17 17:57:58 +01:00
committed by GitHub
parent bb0331ae28
commit 532f7b9923
69 changed files with 1498 additions and 901 deletions

View File

@ -50,7 +50,7 @@ where
T: Transform<S, Req>,
T::Future: 'static,
T::Response: MapServiceResponseBody,
Error: From<T::Error>,
T::Error: Into<Error>,
{
type Response = ServiceResponse;
type Error = Error;
@ -75,7 +75,7 @@ impl<S, Req> Service<Req> for CompatMiddleware<S>
where
S: Service<Req>,
S::Response: MapServiceResponseBody,
Error: From<S::Error>,
S::Error: Into<Error>,
{
type Response = ServiceResponse;
type Error = Error;
@ -99,12 +99,16 @@ impl<Fut, T, E> Future for CompatMiddlewareFuture<Fut>
where
Fut: Future<Output = Result<T, E>>,
T: MapServiceResponseBody,
Error: From<E>,
E: Into<Error>,
{
type Output = Result<ServiceResponse, Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let res = ready!(self.project().fut.poll(cx))?;
let res = match ready!(self.project().fut.poll(cx)) {
Ok(res) => res,
Err(err) => return Poll::Ready(Err(err.into())),
};
Poll::Ready(Ok(res.map_body()))
}
}

View File

@ -13,7 +13,6 @@ use actix_http::{
body::{MessageBody, ResponseBody},
encoding::Encoder,
http::header::{ContentEncoding, ACCEPT_ENCODING},
Error,
};
use actix_service::{Service, Transform};
use actix_utils::future::{ok, Ready};
@ -23,6 +22,7 @@ use pin_project::pin_project;
use crate::{
dev::BodyEncoding,
service::{ServiceRequest, ServiceResponse},
Error,
};
/// Middleware for compressing response payloads.

View File

@ -13,8 +13,8 @@ use futures_core::{future::LocalBoxFuture, ready};
use crate::{
dev::{ServiceRequest, ServiceResponse},
error::{Error, Result},
http::StatusCode,
Error, Result,
};
/// Return type for [`ErrorHandlers`] custom handlers.