pub struct CatchUnwind;Expand description
middleware for catching panic inside Service::call and return a 500 error response.
§Examples:
// handler function that cause panic.
async fn handler(_: &WebContext<'_>) -> &'static str {
panic!("");
}
App::new()
// request to "/" would always panic due to handler function.
.at("/", handler_service(handler))
// enclosed application with CatchUnwind middleware.
// panic in handler function would be caught and converted to 500 internal server error response to client.
.enclosed(CatchUnwind);
// CatchUnwind can also be used on individual route service for scoped panic catching:
App::new()
.at("/", handler_service(handler))
// only catch panic on "/scope" path.
.at("/scope", handler_service(handler).enclosed(CatchUnwind));Trait Implementations§
Source§impl Clone for CatchUnwind
impl Clone for CatchUnwind
Source§fn clone(&self) -> CatchUnwind
fn clone(&self) -> CatchUnwind
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Arg> Service<Arg> for CatchUnwindwhere
CatchUnwind: Service<Arg>,
impl<Arg> Service<Arg> for CatchUnwindwhere
CatchUnwind: Service<Arg>,
Auto Trait Implementations§
impl Freeze for CatchUnwind
impl RefUnwindSafe for CatchUnwind
impl Send for CatchUnwind
impl Sync for CatchUnwind
impl Unpin for CatchUnwind
impl UnsafeUnpin for CatchUnwind
impl UnwindSafe for CatchUnwind
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<S, Arg> ServiceExt<Arg> for Swhere
S: Service<Arg>,
impl<S, Arg> ServiceExt<Arg> for Swhere
S: Service<Arg>,
Source§fn enclosed<T>(self, build: T) -> Pipeline<Self, T, BuildEnclosed>
fn enclosed<T>(self, build: T) -> Pipeline<Self, T, BuildEnclosed>
Enclose Self with given
T as Service<<Self as Service<_>>::Response>>. In other word T
would take Self’s Service::Response type as it’s generic argument of Service<_> impl.Source§fn enclosed_fn<T, Req, O>(
self,
func: T,
) -> Pipeline<Self, AsyncFn<T>, BuildEnclosed>
fn enclosed_fn<T, Req, O>( self, func: T, ) -> Pipeline<Self, AsyncFn<T>, BuildEnclosed>
Function version of Self::enclosed method.
Source§fn map<F, Res, ResMap>(self, mapper: F) -> Pipeline<Self, Map<F>, BuildEnclosed>
fn map<F, Res, ResMap>(self, mapper: F) -> Pipeline<Self, Map<F>, BuildEnclosed>
Mutate
<<Self::Response as Service<Req>>::Future as Future>::Output type with given
closure.