Skip to content

Commit

Permalink
feat(body): identify aborted body write errors
Browse files Browse the repository at this point in the history
(cherry picked from commit bb365f6)
  • Loading branch information
sfackler authored and seanmonstar committed Sep 13, 2019
1 parent c83b54d commit 3286922
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/body/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
12 changes: 12 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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)> {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 3286922

Please sign in to comment.