Skip to content

Commit 3286922

Browse files
sfacklerseanmonstar
authored andcommitted
feat(body): identify aborted body write errors
(cherry picked from commit bb365f6)
1 parent c83b54d commit 3286922

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/body/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Body {
247247
ref mut abort_rx,
248248
} => {
249249
if let Ok(Async::Ready(())) = abort_rx.poll() {
250-
return Err(::Error::new_body_write("body write aborted"));
250+
return Err(::Error::new_body_write_aborted());
251251
}
252252

253253
match rx.poll().expect("mpsc cannot error") {

src/error.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub(crate) enum Kind {
4747
Body,
4848
/// Error while writing a body to connection.
4949
BodyWrite,
50+
/// The body write was aborted.
51+
BodyWriteAborted,
5052
/// Error calling AsyncWrite::shutdown()
5153
Shutdown,
5254

@@ -133,6 +135,11 @@ impl Error {
133135
self.inner.kind == Kind::IncompleteMessage
134136
}
135137

138+
/// Returns true if the body write was aborted.
139+
pub fn is_body_write_aborted(&self) -> bool {
140+
self.inner.kind == Kind::BodyWriteAborted
141+
}
142+
136143
#[doc(hidden)]
137144
#[cfg_attr(error_source, deprecated(note = "use Error::source instead"))]
138145
pub fn cause2(&self) -> Option<&(dyn StdError + 'static + Sync + Send)> {
@@ -250,6 +257,10 @@ impl Error {
250257
Error::new(Kind::BodyWrite).with(cause)
251258
}
252259

260+
pub(crate) fn new_body_write_aborted() -> Error {
261+
Error::new(Kind::BodyWriteAborted)
262+
}
263+
253264
fn new_user(user: User) -> Error {
254265
Error::new(Kind::User(user))
255266
}
@@ -352,6 +363,7 @@ impl StdError for Error {
352363
Kind::Accept => "error accepting connection",
353364
Kind::Body => "error reading a body from connection",
354365
Kind::BodyWrite => "error writing a body to connection",
366+
Kind::BodyWriteAborted => "body write aborted",
355367
Kind::Shutdown => "error shutting down connection",
356368
Kind::Http2 => "http2 error",
357369
Kind::Io => "connection error",

0 commit comments

Comments
 (0)