macro_rules! panic_with_status {
    () => { ... };
    ($status:expr) => { ... };
    ($status:expr, $($arg:tt)*) => { ... };
}
Expand description

Send a response to the client with the given HTTP status code, and then panic.

By default, Rust panics will cause a generic 500 Internal Server Error response to be sent to the client, if a response has not already been sent. This macro allows you to customize the status code, although the response is still generic.

The syntax is similar to panic!(), but takes an optional first argument that must implement ToStatusCode, such as StatusCode or u16. The optional message and format arguments are passed to panic!() unchanged, and so will be printed to the logging endpoint specified by set_panic_endpoint().

Examples

let req = Request::get("https://example.com/bad_path");
if req.get_path().starts_with("bad") {
    panic_with_status!(403, "forbade request to a bad path: {}", req.get_url_str());
}