From 3286922460ab63d0a804d8170d862ff4ba5951dd Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 12 Sep 2019 17:46:00 -0700 Subject: [PATCH] feat(body): identify aborted body write errors (cherry picked from commit bb365f689defcf529bf546eb684177dbe801b0ba) --- src/body/body.rs | 2 +- src/error.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/body/body.rs b/src/body/body.rs index 00da58c5c6..9a1373cf91 100644 --- a/src/body/body.rs +++ b/src/body/body.rs @@ -247,7 +247,7 @@ impl Body { ref mut abort_rx, } => { if let Ok(Async::Ready(())) = abort_rx.poll() { - return Err(::Error::new_body_write("body write aborted")); + return Err(::Error::new_body_write_aborted()); } match rx.poll().expect("mpsc cannot error") { diff --git a/src/error.rs b/src/error.rs index 251d867152..c9d56db363 100644 --- a/src/error.rs +++ b/src/error.rs @@ -47,6 +47,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, @@ -133,6 +135,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 + } + #[doc(hidden)] #[cfg_attr(error_source, deprecated(note = "use Error::source instead"))] pub fn cause2(&self) -> Option<&(dyn StdError + 'static + Sync + Send)> { @@ -250,6 +257,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)) } @@ -352,6 +363,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",