Struct ajars_actix_web::actix_web::middleware::ErrorHandlers [−][src]
pub struct ErrorHandlers<B> { /* fields omitted */ }
Expand description
Middleware for registering custom status code based error handlers.
Register handlers with the ErrorHandlers::handler()
method to register a custom error handler
for a given status code. Handlers can modify existing responses or create completely new ones.
Examples
use actix_web::middleware::{ErrorHandlers, ErrorHandlerResponse}; use actix_web::{web, http, dev, App, HttpRequest, HttpResponse, Result}; fn render_500<B>(mut res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> { res.response_mut() .headers_mut() .insert(http::header::CONTENT_TYPE, http::HeaderValue::from_static("Error")); Ok(ErrorHandlerResponse::Response(res)) } let app = App::new() .wrap( ErrorHandlers::new() .handler(http::StatusCode::INTERNAL_SERVER_ERROR, render_500), ) .service(web::resource("/test") .route(web::get().to(|| HttpResponse::Ok())) .route(web::head().to(|| HttpResponse::MethodNotAllowed()) ));
Implementations
Construct new ErrorHandlers
instance.
pub fn handler<F>(self, status: StatusCode, handler: F) -> ErrorHandlers<B> where
F: Fn(ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>, Error> + 'static,
pub fn handler<F>(self, status: StatusCode, handler: F) -> ErrorHandlers<B> where
F: Fn(ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>, Error> + 'static,
Register error handler for specified status code.
Trait Implementations
Returns the “default value” for a type. Read more
impl<S, B> Transform<S, ServiceRequest> for ErrorHandlers<B> where
B: 'static,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
<S as Service<ServiceRequest>>::Future: 'static,
impl<S, B> Transform<S, ServiceRequest> for ErrorHandlers<B> where
B: 'static,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
<S as Service<ServiceRequest>>::Future: 'static,
type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
type Transform = ErrorHandlersMiddleware<S, B>
type Transform = ErrorHandlersMiddleware<S, B>
The TransformService
value created by this factory
type Future = Pin<Box<dyn Future<Output = Result<<ErrorHandlers<B> as Transform<S, ServiceRequest>>::Transform, <ErrorHandlers<B> as Transform<S, ServiceRequest>>::InitError>> + 'static, Global>>
type Future = Pin<Box<dyn Future<Output = Result<<ErrorHandlers<B> as Transform<S, ServiceRequest>>::Transform, <ErrorHandlers<B> as Transform<S, ServiceRequest>>::InitError>> + 'static, Global>>
The future response value.
pub fn new_transform(
&self,
service: S
) -> <ErrorHandlers<B> as Transform<S, ServiceRequest>>::Future
pub fn new_transform(
&self,
service: S
) -> <ErrorHandlers<B> as Transform<S, ServiceRequest>>::Future
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations
impl<B> !RefUnwindSafe for ErrorHandlers<B>
impl<B> !Send for ErrorHandlers<B>
impl<B> !Sync for ErrorHandlers<B>
impl<B> Unpin for ErrorHandlers<B>
impl<B> !UnwindSafe for ErrorHandlers<B>