---
title: panic_with_status
summary: Send a response to the client with the given HTTP status code, and then panic.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/macro.panic_with_status/
---

**Kind:** Macro  
**Module:** [fastly](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/response.rs#2069

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

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!()`](https://doc.rust-lang.org/stable/std/macro.panic.html), but takes an optional first argument that must implement
[`ToStatusCode`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToStatusCode/), such as [`StatusCode`](https://docs.rs/http/latest/http/status/struct.StatusCode.html) or [`u16`](https://doc.rust-lang.org/stable/std/primitive.u16.html). The optional message and format arguments
are passed to [`panic!()`](https://doc.rust-lang.org/stable/std/macro.panic.html) unchanged, and so will be printed to the logging endpoint specified
by [`set_panic_endpoint()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/log/fn.set_panic_endpoint/).

## Examples

```rust
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());
}
```
