feat(body): identify aborted body write errors
This commit is contained in:
committed by
Sean McArthur
parent
2b0405c48c
commit
dc54ee199f
@@ -260,7 +260,7 @@ impl Body {
|
||||
ref mut abort_rx,
|
||||
} => {
|
||||
if let Poll::Ready(Ok(())) = Pin::new(abort_rx).poll(cx) {
|
||||
return Poll::Ready(Some(Err(crate::Error::new_body_write("body write aborted"))));
|
||||
return Poll::Ready(Some(Err(crate::Error::new_body_write_aborted())));
|
||||
}
|
||||
|
||||
match ready!(Pin::new(rx).poll_next(cx)?) {
|
||||
|
||||
12
src/error.rs
12
src/error.rs
@@ -43,6 +43,8 @@ pub(crate) enum Kind {
|
||||
Body,
|
||||
/// Error while writing a body to connection.
|
||||
BodyWrite,
|
||||
/// The body write was aborted.
|
||||
BodyWriteAborted,
|
||||
/// Error calling AsyncWrite::shutdown()
|
||||
Shutdown,
|
||||
|
||||
@@ -129,6 +131,11 @@ impl Error {
|
||||
self.inner.kind == Kind::IncompleteMessage
|
||||
}
|
||||
|
||||
/// Returns true if the body write was aborted.
|
||||
pub fn is_body_write_aborted(&self) -> bool {
|
||||
self.inner.kind == Kind::BodyWriteAborted
|
||||
}
|
||||
|
||||
/// Consumes the error, returning its cause.
|
||||
pub fn into_cause(self) -> Option<Box<dyn StdError + Send + Sync>> {
|
||||
self.inner.cause
|
||||
@@ -218,6 +225,10 @@ impl Error {
|
||||
Error::new(Kind::BodyWrite).with(cause)
|
||||
}
|
||||
|
||||
pub(crate) fn new_body_write_aborted() -> Error {
|
||||
Error::new(Kind::BodyWriteAborted)
|
||||
}
|
||||
|
||||
fn new_user(user: User) -> Error {
|
||||
Error::new(Kind::User(user))
|
||||
}
|
||||
@@ -320,6 +331,7 @@ impl StdError for Error {
|
||||
Kind::Accept => "error accepting connection",
|
||||
Kind::Body => "error reading a body from connection",
|
||||
Kind::BodyWrite => "error writing a body to connection",
|
||||
Kind::BodyWriteAborted => "body write aborted",
|
||||
Kind::Shutdown => "error shutting down connection",
|
||||
Kind::Http2 => "http2 error",
|
||||
Kind::Io => "connection error",
|
||||
|
||||
Reference in New Issue
Block a user