added body manipulation example for error handlers
Closes
@@ -50,6 +50,8 @@ type DefaultHandler<B> = Option<Rc<ErrorHandler<B>>>;
/// will pass by unchanged by this middleware.
///
/// # Examples
+/// ## Handler Response
+/// Header
/// ```
/// use actix_web::http::{header, StatusCode};
/// use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers};
@@ -67,6 +69,28 @@ type DefaultHandler<B> = Option<Rc<ErrorHandler<B>>>;
/// .wrap(ErrorHandlers::new().handler(StatusCode::INTERNAL_SERVER_ERROR, add_error_header))
/// .service(web::resource("/").route(web::get().to(HttpResponse::InternalServerError)));
/// ```
+///
+/// Body Content
+/// ```
+/// use actix_web::http::{header, StatusCode};
+/// use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers};
+/// use actix_web::{dev, web, App, HttpResponse, Result};
+/// fn add_error_body<B>(res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> {
+/// // Get the error message and status code
+/// let error_message = "An error occurred";
+/// // Destructures ServiceResponse into request and response components
+/// let (req, res) = res.into_parts();
+/// // Create a new response with the modified body
+/// let res = res.set_body(error_message).map_into_boxed_body();
+/// // Create a new ServiceResponse with the modified response
+/// let res = dev::ServiceResponse::new(req, res).map_into_right_body();
+/// Ok(ErrorHandlerResponse::Response(res))
+///}
+///
+/// let app = App::new()
+/// .wrap(ErrorHandlers::new().handler(StatusCode::INTERNAL_SERVER_ERROR, add_error_body))
+/// .service(web::resource("/").route(web::get().to(HttpResponse::InternalServerError)));
+/// ```
/// ## Registering default handler
/// ```
/// # use actix_web::http::{header, StatusCode};
