mirror of
https://github.com/actix/actix-web.git
synced 2024-12-01 22:11:20 +00:00
include source for dispatch body errors
This commit is contained in:
parent
a2467718ac
commit
5359fa56c2
4 changed files with 31 additions and 32 deletions
|
@ -332,31 +332,28 @@ impl From<PayloadError> for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of errors that can occur during dispatching HTTP requests.
|
/// A set of errors that can occur during dispatching HTTP requests.
|
||||||
#[derive(Debug, Display, Error, From)]
|
#[derive(Debug, Display, From)]
|
||||||
#[non_exhaustive]
|
|
||||||
pub enum DispatchError {
|
pub enum DispatchError {
|
||||||
/// Service error
|
/// Service error.
|
||||||
// FIXME: display and error type
|
|
||||||
#[display(fmt = "Service Error")]
|
#[display(fmt = "Service Error")]
|
||||||
Service(#[error(not(source))] Response<BoxBody>),
|
Service(Response<BoxBody>),
|
||||||
|
|
||||||
/// Body error
|
/// Body streaming error.
|
||||||
// FIXME: display and error type
|
#[display(fmt = "Body error: {}", _0)]
|
||||||
#[display(fmt = "Body Error")]
|
Body(Box<dyn StdError>),
|
||||||
Body(#[error(not(source))] Box<dyn StdError>),
|
|
||||||
|
|
||||||
/// Upgrade service error
|
/// Upgrade service error.
|
||||||
Upgrade,
|
Upgrade,
|
||||||
|
|
||||||
/// An `io::Error` that occurred while trying to read or write to a network stream.
|
/// An `io::Error` that occurred while trying to read or write to a network stream.
|
||||||
#[display(fmt = "IO error: {}", _0)]
|
#[display(fmt = "IO error: {}", _0)]
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
|
|
||||||
/// Http request parse error.
|
/// Request parse error.
|
||||||
#[display(fmt = "Parse error: {}", _0)]
|
#[display(fmt = "Request parse error: {}", _0)]
|
||||||
Parse(ParseError),
|
Parse(ParseError),
|
||||||
|
|
||||||
/// Http/2 error
|
/// HTTP/2 error.
|
||||||
#[display(fmt = "{}", _0)]
|
#[display(fmt = "{}", _0)]
|
||||||
H2(h2::Error),
|
H2(h2::Error),
|
||||||
|
|
||||||
|
@ -368,21 +365,23 @@ pub enum DispatchError {
|
||||||
#[display(fmt = "Connection shutdown timeout")]
|
#[display(fmt = "Connection shutdown timeout")]
|
||||||
DisconnectTimeout,
|
DisconnectTimeout,
|
||||||
|
|
||||||
/// Payload is not consumed
|
/// Internal error.
|
||||||
#[display(fmt = "Task is completed but request's payload is not consumed")]
|
|
||||||
PayloadIsNotConsumed,
|
|
||||||
|
|
||||||
/// Malformed request
|
|
||||||
#[display(fmt = "Malformed request")]
|
|
||||||
MalformedRequest,
|
|
||||||
|
|
||||||
/// Internal error
|
|
||||||
#[display(fmt = "Internal error")]
|
#[display(fmt = "Internal error")]
|
||||||
InternalError,
|
InternalError,
|
||||||
|
}
|
||||||
|
|
||||||
/// Unknown error
|
impl StdError for DispatchError {
|
||||||
#[display(fmt = "Unknown error")]
|
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
||||||
Unknown,
|
match self {
|
||||||
|
// TODO: error source extraction?
|
||||||
|
DispatchError::Service(_res) => None,
|
||||||
|
DispatchError::Body(err) => Some(&**err),
|
||||||
|
DispatchError::Io(err) => Some(err),
|
||||||
|
DispatchError::Parse(err) => Some(err),
|
||||||
|
DispatchError::H2(err) => Some(err),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of error that can occur during parsing content type.
|
/// A set of error that can occur during parsing content type.
|
||||||
|
|
|
@ -458,7 +458,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Ready(Some(Err(err))) => {
|
Poll::Ready(Some(Err(err))) => {
|
||||||
return Err(DispatchError::Service(err.into()))
|
return Err(DispatchError::Body(err.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Pending => return Ok(PollResponse::DoNothing),
|
Poll::Pending => return Ok(PollResponse::DoNothing),
|
||||||
|
|
|
@ -356,9 +356,9 @@ where
|
||||||
type Future = Dispatcher<T, S, B, X, U>;
|
type Future = Dispatcher<T, S, B, X, U>;
|
||||||
|
|
||||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
self._poll_ready(cx).map_err(|e| {
|
self._poll_ready(cx).map_err(|err| {
|
||||||
log::error!("HTTP/1 service readiness error: {:?}", e);
|
log::error!("HTTP/1 service readiness error: {:?}", err);
|
||||||
DispatchError::Service(e)
|
DispatchError::Service(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -493,9 +493,9 @@ where
|
||||||
type Future = HttpServiceHandlerResponse<T, S, B, X, U>;
|
type Future = HttpServiceHandlerResponse<T, S, B, X, U>;
|
||||||
|
|
||||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
self._poll_ready(cx).map_err(|e| {
|
self._poll_ready(cx).map_err(|err| {
|
||||||
log::error!("HTTP service readiness error: {:?}", e);
|
log::error!("HTTP service readiness error: {:?}", err);
|
||||||
DispatchError::Service(e)
|
DispatchError::Service(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue