[][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(Error).

  • 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(Error::new(status_code, message, expose));

Example

use roa_core::{App, throw};
use roa_core::http::StatusCode;

let mut app = App::new(());
app.gate_fn(|mut ctx, next| async move {
    next.await?; // throw
    unreachable!();
    ctx.resp_mut().status = StatusCode::OK;
    Ok(())
});
app.end(|_ctx| async {
    throw!(StatusCode::IM_A_TEAPOT, "I'm a teapot!"); // throw
    unreachable!()
});