Skip to content

Commit

Permalink
expose app error by http service
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Oct 1, 2018
1 parent c1e0b4f commit 2217a15
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,9 @@ impl Default for ClientConnector {
Arc::new(config)
}

#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg(not(any(
feature = "alpn",
feature = "ssl",
feature = "tls",
feature = "rust-tls",
)))]
feature = "alpn", feature = "ssl", feature = "tls", feature = "rust-tls")))]
{
()
}
Expand Down
14 changes: 12 additions & 2 deletions src/server/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub enum AcceptorError<T> {
/// A set of errors that can occur during dispatching http requests
pub enum HttpDispatchError {
/// Application error
#[fail(display = "Application specific error")]
AppError,
#[fail(display = "Application specific error: {}", _0)]
App(Error),

/// An `io::Error` that occurred while trying to read or write to a network
/// stream.
Expand All @@ -39,6 +39,16 @@ pub enum HttpDispatchError {
/// HTTP2 error
#[fail(display = "HTTP2 error: {}", _0)]
Http2(http2::Error),

/// Unknown error
#[fail(display = "Unknown error")]
Unknown,
}

impl From<Error> for HttpDispatchError {
fn from(err: Error) -> Self {
HttpDispatchError::App(err)
}
}

impl From<io::Error> for HttpDispatchError {
Expand Down
14 changes: 11 additions & 3 deletions src/server/h1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub(crate) struct Http1<T: IoStream, H: HttpHandler + 'static> {
payload: Option<PayloadType>,
buf: BytesMut,
tasks: VecDeque<Entry<H>>,
error: Option<Error>,
ka_enabled: bool,
ka_expire: Instant,
ka_timer: Option<Delay>,
Expand Down Expand Up @@ -113,6 +114,7 @@ where
decoder: H1Decoder::new(),
payload: None,
tasks: VecDeque::new(),
error: None,
addr,
buf,
settings,
Expand Down Expand Up @@ -321,7 +323,11 @@ where
return Ok(Async::NotReady);
}
self.flags.insert(Flags::ERROR);
return Err(HttpDispatchError::AppError);
return Err(self
.error
.take()
.map(|e| e.into())
.unwrap_or(HttpDispatchError::Unknown));
}

match self.tasks[idx].pipe.poll_io(&mut self.stream) {
Expand Down Expand Up @@ -357,12 +363,13 @@ where
io = true;
}
Err(err) => {
error!("Unhandled error1: {}", err);
// it is not possible to recover from error
// during pipe handling, so just drop connection
self.read_disconnected();
self.write_disconnected();
self.tasks[idx].flags.insert(EntryFlags::ERROR);
error!("Unhandled error1: {}", err);
self.error = Some(err);
continue;
}
}
Expand All @@ -373,10 +380,11 @@ where
self.tasks[idx].flags.insert(EntryFlags::FINISHED)
}
Err(err) => {
error!("Unhandled error: {}", err);
self.read_disconnected();
self.write_disconnected();
self.tasks[idx].flags.insert(EntryFlags::ERROR);
error!("Unhandled error: {}", err);
self.error = Some(err);
continue;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/server/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl<H> Clone for WorkerSettings<H> {
}

impl<H> WorkerSettings<H> {
/// Create instance of `WorkerSettings`
pub fn new(
handler: H, keep_alive: KeepAlive, client_timeout: u64, settings: ServerSettings,
) -> WorkerSettings<H> {
Expand Down

0 comments on commit 2217a15

Please sign in to comment.