mirror of
https://github.com/actix/actix-web.git
synced 2024-11-23 10:01:06 +00:00
expose app error by http service
This commit is contained in:
parent
c1e0b4f322
commit
2217a152cb
4 changed files with 26 additions and 10 deletions
|
@ -285,12 +285,9 @@ impl Default for ClientConnector {
|
||||||
Arc::new(config)
|
Arc::new(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
#[cfg(not(any(
|
#[cfg(not(any(
|
||||||
feature = "alpn",
|
feature = "alpn", feature = "ssl", feature = "tls", feature = "rust-tls")))]
|
||||||
feature = "ssl",
|
|
||||||
feature = "tls",
|
|
||||||
feature = "rust-tls",
|
|
||||||
)))]
|
|
||||||
{
|
{
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ pub enum AcceptorError<T> {
|
||||||
/// A set of errors that can occur during dispatching http requests
|
/// A set of errors that can occur during dispatching http requests
|
||||||
pub enum HttpDispatchError {
|
pub enum HttpDispatchError {
|
||||||
/// Application error
|
/// Application error
|
||||||
#[fail(display = "Application specific error")]
|
#[fail(display = "Application specific error: {}", _0)]
|
||||||
AppError,
|
App(Error),
|
||||||
|
|
||||||
/// An `io::Error` that occurred while trying to read or write to a network
|
/// An `io::Error` that occurred while trying to read or write to a network
|
||||||
/// stream.
|
/// stream.
|
||||||
|
@ -39,6 +39,16 @@ pub enum HttpDispatchError {
|
||||||
/// HTTP2 error
|
/// HTTP2 error
|
||||||
#[fail(display = "HTTP2 error: {}", _0)]
|
#[fail(display = "HTTP2 error: {}", _0)]
|
||||||
Http2(http2::Error),
|
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 {
|
impl From<io::Error> for HttpDispatchError {
|
||||||
|
|
|
@ -49,6 +49,7 @@ pub(crate) struct Http1<T: IoStream, H: HttpHandler + 'static> {
|
||||||
payload: Option<PayloadType>,
|
payload: Option<PayloadType>,
|
||||||
buf: BytesMut,
|
buf: BytesMut,
|
||||||
tasks: VecDeque<Entry<H>>,
|
tasks: VecDeque<Entry<H>>,
|
||||||
|
error: Option<Error>,
|
||||||
ka_enabled: bool,
|
ka_enabled: bool,
|
||||||
ka_expire: Instant,
|
ka_expire: Instant,
|
||||||
ka_timer: Option<Delay>,
|
ka_timer: Option<Delay>,
|
||||||
|
@ -113,6 +114,7 @@ where
|
||||||
decoder: H1Decoder::new(),
|
decoder: H1Decoder::new(),
|
||||||
payload: None,
|
payload: None,
|
||||||
tasks: VecDeque::new(),
|
tasks: VecDeque::new(),
|
||||||
|
error: None,
|
||||||
addr,
|
addr,
|
||||||
buf,
|
buf,
|
||||||
settings,
|
settings,
|
||||||
|
@ -321,7 +323,11 @@ where
|
||||||
return Ok(Async::NotReady);
|
return Ok(Async::NotReady);
|
||||||
}
|
}
|
||||||
self.flags.insert(Flags::ERROR);
|
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) {
|
match self.tasks[idx].pipe.poll_io(&mut self.stream) {
|
||||||
|
@ -357,12 +363,13 @@ where
|
||||||
io = true;
|
io = true;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
error!("Unhandled error1: {}", err);
|
||||||
// it is not possible to recover from error
|
// it is not possible to recover from error
|
||||||
// during pipe handling, so just drop connection
|
// during pipe handling, so just drop connection
|
||||||
self.read_disconnected();
|
self.read_disconnected();
|
||||||
self.write_disconnected();
|
self.write_disconnected();
|
||||||
self.tasks[idx].flags.insert(EntryFlags::ERROR);
|
self.tasks[idx].flags.insert(EntryFlags::ERROR);
|
||||||
error!("Unhandled error1: {}", err);
|
self.error = Some(err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,10 +380,11 @@ where
|
||||||
self.tasks[idx].flags.insert(EntryFlags::FINISHED)
|
self.tasks[idx].flags.insert(EntryFlags::FINISHED)
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
error!("Unhandled error: {}", err);
|
||||||
self.read_disconnected();
|
self.read_disconnected();
|
||||||
self.write_disconnected();
|
self.write_disconnected();
|
||||||
self.tasks[idx].flags.insert(EntryFlags::ERROR);
|
self.tasks[idx].flags.insert(EntryFlags::ERROR);
|
||||||
error!("Unhandled error: {}", err);
|
self.error = Some(err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,6 +145,7 @@ impl<H> Clone for WorkerSettings<H> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H> WorkerSettings<H> {
|
impl<H> WorkerSettings<H> {
|
||||||
|
/// Create instance of `WorkerSettings`
|
||||||
pub fn new(
|
pub fn new(
|
||||||
handler: H, keep_alive: KeepAlive, client_timeout: u64, settings: ServerSettings,
|
handler: H, keep_alive: KeepAlive, client_timeout: u64, settings: ServerSettings,
|
||||||
) -> WorkerSettings<H> {
|
) -> WorkerSettings<H> {
|
||||||
|
|
Loading…
Reference in a new issue