From 3a502055bfcd8c620234500df5b02a51a1bef092 Mon Sep 17 00:00:00 2001 From: asonix Date: Thu, 12 Sep 2019 20:17:29 -0500 Subject: [PATCH] Forward upstream errors --- .../src/digest/middleware.rs | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/http-signature-normalization-actix/src/digest/middleware.rs b/http-signature-normalization-actix/src/digest/middleware.rs index 5f568ea..046bc1d 100644 --- a/http-signature-normalization-actix/src/digest/middleware.rs +++ b/http-signature-normalization-actix/src/digest/middleware.rs @@ -18,10 +18,6 @@ use super::{DigestPart, DigestVerify}; pub struct VerifyDigest(bool, T); pub struct VerifyMiddleware(Rc>, bool, T); -#[derive(Debug, Fail)] -#[fail(display = "Error in upstream middleware")] -pub struct UpstreamError; - #[derive(Debug, Fail)] #[fail(display = "Error verifying digest")] pub struct VerifyError; @@ -42,7 +38,11 @@ where impl Transform for VerifyDigest where T: DigestVerify + Clone + 'static, - S: Service> + 'static, + S: Service< + Request = ServiceRequest, + Response = ServiceResponse, + Error = actix_web::Error, + > + 'static, S::Error: 'static, { type Request = ServiceRequest; @@ -64,7 +64,11 @@ where impl Service for VerifyMiddleware where T: DigestVerify + Clone + 'static, - S: Service> + 'static, + S: Service< + Request = ServiceRequest, + Response = ServiceResponse, + Error = actix_web::Error, + > + 'static, S::Error: 'static, { type Request = ServiceRequest; @@ -73,10 +77,7 @@ where type Future = Box>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { - self.0 - .borrow_mut() - .poll_ready() - .map_err(|_| UpstreamError.into()) + self.0.borrow_mut().poll_ready() } fn call(&mut self, mut req: ServiceRequest) -> Self::Future { @@ -97,12 +98,7 @@ where .into(), ); - Either::A( - service - .borrow_mut() - .call(req) - .map_err(|_| UpstreamError.into()), - ) + Either::A(service.borrow_mut().call(req)) } else { Either::B(err(VerifyError.into())) } @@ -111,12 +107,7 @@ where if self.1 { Box::new(err(VerifyError.into())) } else { - Box::new( - self.0 - .borrow_mut() - .call(req) - .map_err(|_| UpstreamError.into()), - ) + Box::new(self.0.borrow_mut().call(req)) } } } @@ -144,16 +135,6 @@ fn parse_digest(h: &HeaderValue) -> Option> { } } -impl ResponseError for UpstreamError { - fn error_response(&self) -> HttpResponse { - HttpResponse::InternalServerError().finish() - } - - fn render_response(&self) -> HttpResponse { - Self::error_response(self) - } -} - impl ResponseError for VerifyError { fn error_response(&self) -> HttpResponse { HttpResponse::BadRequest().finish()