Skip to main content

rok_exception

Macro rok_exception 

Source
macro_rules! rok_exception {
    (
        $(#[$meta:meta])*
        $vis:vis struct $name:ident {
            status = $status:expr,
            self_handled = true,
            translation = $translation:expr,
            fields: { $(pub $field:ident: $ty:ty),* $(,)? }
        }
    ) => { ... };
    (
        $(#[$meta:meta])*
        $vis:vis struct $name:ident {
            status = $status:expr,
            self_handled = true,
            fields: { $(pub $field:ident: $ty:ty),* $(,)? }
        }
    ) => { ... };
    (
        $(#[$meta:meta])*
        $vis:vis struct $name:ident {
            status = $status:expr,
            self_handled = false,
            translation = $translation:expr,
            fields: { $(pub $field:ident: $ty:ty),* $(,)? }
        }
    ) => { ... };
    (
        $(#[$meta:meta])*
        $vis:vis struct $name:ident {
            status = $status:expr,
            self_handled = false,
            fields: { $(pub $field:ident: $ty:ty),* $(,)? }
        }
    ) => { ... };
    (
        $(#[$meta:meta])*
        $vis:vis struct $name:ident {
            status = $status:expr,
            fields: { $(pub $field:ident: $ty:ty),* $(,)? }
        }
    ) => { ... };
}
Expand description

Define a typed exception struct implementing RokException.

Self-handled exceptions (default) also implement axum::IntoResponse when the axum feature is enabled.

§Example

use rok_core::rok_exception;

rok_exception! {
    /// Raised when a query returns no rows.
    pub struct E_ROW_NOT_FOUND {
        status = 404,
        self_handled = false,
        fields: {
            pub model: Option<&'static str>,
            pub id: Option<String>,
        },
    }
}