Expand description
Error pages (18.35.0, #95): what the client sees when a handler panics
or the app returns an error, depending on RwsEnv.
- In
devandtest: the panic message, where it happened, the request and the backtrace — an HTML page for a browser, problem details withlocationandbacktracemembers for anything else. - In
prod:500problem details without any of it; the details go to stderr.
use rust_web_server::app::App;
use rust_web_server::error_pages::ErrorPages;
use rust_web_server::response::Response;
use rust_web_server::test_client::TestClient;
let app = App::with_state(())
.get("/boom", |_, _, _, _| -> Response { panic!("the cache is empty") })
.wrap(ErrorPages::detailed(true)); // ErrorPages::from_env() reads RWS_ENV
let response = TestClient::new(app).get("/boom").header("Accept", "text/html").send();
assert_eq!(500, response.status());
assert!(response.body_text().contains("the cache is empty"));With details on, every request goes through the layer on the blocking
pool (async handlers included), so their panics can be caught; with them
off, requests pass straight through and the server’s own panic handling
answers 500.
Structs§
- Error
Pages - The error-page middleware. See the module docs.