Skip to main content

ensure_code

Macro ensure_code 

Source
macro_rules! ensure_code {
    ($condition:expr, $ctx:expr, $($error:tt)+) => { ... };
}
Expand description

Return an error of a chosen code unless a condition holds.

ensure! with the code spelled out — for a guard that is a denial, a conflict, or anything else a 422 would misdescribe.

fn delete(owner: &str, actor: &str, ctx: &Context) -> Result<(), JsonApiError> {
    ash_jsonapi::ensure_code!(
        owner == actor,
        ctx,
        ErrorCode::Forbidden,
        "only the owner may delete this todo"
    );
    Ok(())
}