1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00

expose app error by http service

This commit is contained in:
Nikolay Kim 2018-10-01 15:19:49 -07:00
parent c1e0b4f322
commit 2217a152cb
4 changed files with 26 additions and 10 deletions

View File

@ -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")))]
{
()
}

View File

@ -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.
@ -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 {

View File

@ -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>,
@ -113,6 +114,7 @@ where
decoder: H1Decoder::new(),
payload: None,
tasks: VecDeque::new(),
error: None,
addr,
buf,
settings,
@ -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) {
@ -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;
}
}
@ -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;
}
}

View File

@ -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> {