macro_rules! http_error {
($status_code:ident, $reason:literal) => { ... };
($status_code:ident $(, source = $src:expr)? $(, reason = $($arg:tt)*)?) => { ... };
($status_code:ident $(, $($arg:tt)*)?) => { ... };
}
Expand description
Construct an ad-hoc Error
from a status code, optional source error and formatted reason.
fn foo() -> anyhow::Result<()> {
const CODE: i32 = 1234;
Err(http_error!(BAD_REQUEST, "invalid payload, code {}", CODE))?;
// with source
let source = anyhow!("source error");
Err(http_error!(BAD_REQUEST, source = source, reason = "invalid payload, code {}", CODE))?;
Ok(())
}