macro_rules! throw {
($status_code:expr) => { ... };
($status_code:expr, $message:expr) => { ... };
($status_code:expr, $message:expr, $expose:expr) => { ... };
}
Expand description
Throw an Err(Status)
.
throw!(status_code)
will be expanded tothrow!(status_code, "")
throw!(status_code, message)
will be expanded tothrow!(status_code, message, true)
throw!(status_code, message, expose)
will be expanded toreturn Err(Status::new(status_code, message, expose));
Example
use roa_core::{App, Context, Next, Result, throw};
use roa_core::http::StatusCode;
let app = App::new().gate(gate).end(end);
async fn gate(ctx: &mut Context, next: Next<'_>) -> Result {
next.await?; // throw
unreachable!();
ctx.resp.status = StatusCode::OK;
Ok(())
}
async fn end(ctx: &mut Context) -> Result {
throw!(StatusCode::IM_A_TEAPOT, "I'm a teapot!"); // throw
unreachable!()
}