Struct actix_web::middleware::errhandlers::ErrorHandlers [−][src]
pub struct ErrorHandlers<B> { /* fields omitted */ }
Expand description
Middleware
for allowing custom handlers for responses.
You can use ErrorHandlers::handler()
method to register a custom error
handler for specific status code. You can modify existing response or
create completely new one.
Example
use actix_web::middleware::errhandlers::{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
pub fn handler<F>(self, status: StatusCode, handler: F) -> Self where
F: Fn(ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> + 'static,
pub fn handler<F>(self, status: StatusCode, handler: F) -> Self where
F: Fn(ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> + 'static,
Register error handler for specified status code
Trait Implementations
impl<S, B> Transform<S> for ErrorHandlers<B> where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
impl<S, B> Transform<S> for ErrorHandlers<B> where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
type Request = ServiceRequest
type Request = ServiceRequest
Requests handled by the service.
type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses given by the service.
type Transform = ErrorHandlersMiddleware<S, B>
type Transform = ErrorHandlersMiddleware<S, B>
The TransformService
value created by this factory
Creates and returns a new Transform component, asynchronously
fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, F, E> where
F: Fn(Self::InitError) -> E + Clone,
fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, F, E> where
F: Fn(Self::InitError) -> E + Clone,
Map this transforms’s factory error to a different error, returning a new transform service factory. Read more
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>
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more