[−][src]Macro roa_core::throw
Throw an Err(Error)
.
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(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!() });