diff --git a/src/error.rs b/src/error.rs index 877661c6..98e3f0ca 100644 --- a/src/error.rs +++ b/src/error.rs @@ -24,8 +24,8 @@ pub enum Error { #[error("failed generating the response body")] ResponseBody(#[source] BoxError), - #[error("handler service returned an error")] - Service(#[source] BoxError), + #[error("some dynamic error happened")] + Dynamic(#[source] BoxError), #[error("request extension of type `{type_name}` was not set")] MissingExtension { type_name: &'static str }, @@ -49,12 +49,11 @@ pub enum Error { InvalidUtf8, } -impl Error { - /// Create an `Error` from a `BoxError` coming from a `Service` - pub(crate) fn from_service_error(error: BoxError) -> Error { - match error.downcast::() { +impl From for Error { + fn from(err: BoxError) -> Self { + match err.downcast::() { Ok(err) => *err, - Err(err) => Error::Service(err), + Err(err) => Error::Dynamic(err), } } } @@ -94,9 +93,9 @@ where | Error::SerializeResponseBody(_) | Error::UnknownUrlParam(_) => make_response(StatusCode::INTERNAL_SERVER_ERROR), - Error::Service(err) => match err.downcast::() { + Error::Dynamic(err) => match err.downcast::() { Ok(err) => Err(*err), - Err(err) => Err(Error::Service(err)), + Err(err) => Err(Error::Dynamic(err)), }, err @ Error::ConsumeRequestBody(_) => Err(err), diff --git a/src/handler.rs b/src/handler.rs index 24b24405..16e96ce5 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -113,7 +113,7 @@ where self.svc .oneshot(req) .await - .map_err(|err| Error::Service(err.into())) + .map_err(|err| Error::Dynamic(err.into())) } } diff --git a/src/routing.rs b/src/routing.rs index 2c3d128c..8a0abdab 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -381,7 +381,7 @@ where #[inline] fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - self.inner.poll_ready(cx).map_err(Error::from_service_error) + self.inner.poll_ready(cx).map_err(Error::from) } #[inline] @@ -409,7 +409,7 @@ impl Future for BoxServiceTreeResponseFuture { self.project() .inner .poll(cx) - .map_err(Error::from_service_error) + .map_err(Error::from) } }