[][src]Macro roa_core::throw

macro_rules! throw {
    ($status_code:expr) => { ... };
    ($status_code:expr, $message:expr) => { ... };
    ($status_code:expr, $message:expr, $expose:expr) => { ... };
}

Throw an Err(Status).

  • throw!(status_code) will be expanded to throw!(status_code, "")
  • throw!(status_code, message) will be expanded to throw!(status_code, message, true)
  • throw!(status_code, message, expose) will be expanded to return 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!()
}