#![allow(dead_code)] // use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers}; use actix_web::{ dev, http::{header, StatusCode}, web, App, HttpResponse, HttpServer, Result, }; fn add_error_header(mut res: dev::ServiceResponse) -> Result> { res.response_mut().headers_mut().insert( header::CONTENT_TYPE, header::HeaderValue::from_static("Error"), ); Ok(ErrorHandlerResponse::Response(res.map_into_left_body())) } #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .wrap( ErrorHandlers::new() .handler(StatusCode::INTERNAL_SERVER_ERROR, add_error_header), ) .service(web::resource("/").route(web::get().to(HttpResponse::InternalServerError))) }) .bind(("127.0.0.1", 8080))? .run() .await } //