Rename error type

This commit is contained in:
David Pedersen 2021-05-31 20:53:03 +02:00
parent d33be9683c
commit 19cbece1dc
3 changed files with 11 additions and 12 deletions

View file

@ -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::<Error>() {
impl From<BoxError> for Error {
fn from(err: BoxError) -> Self {
match err.downcast::<Error>() {
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>() {
Error::Dynamic(err) => match err.downcast::<Error>() {
Ok(err) => Err(*err),
Err(err) => Err(Error::Service(err)),
Err(err) => Err(Error::Dynamic(err)),
},
err @ Error::ConsumeRequestBody(_) => Err(err),

View file

@ -113,7 +113,7 @@ where
self.svc
.oneshot(req)
.await
.map_err(|err| Error::Service(err.into()))
.map_err(|err| Error::Dynamic(err.into()))
}
}

View file

@ -381,7 +381,7 @@ where
#[inline]
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
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<B> Future for BoxServiceTreeResponseFuture<B> {
self.project()
.inner
.poll(cx)
.map_err(Error::from_service_error)
.map_err(Error::from)
}
}