Derive Macro actix_error::AsApiError

source ·
#[derive(AsApiError)]
{
    // Attributes available to this derive:
    #[error]
}
Expand description

This derive macro is used to convert an enum into an ApiError.
You can use it by adding the #[derive(AsApiError)] attribute to your enum.
By default, the kind is snake case.
#[error(kind = "your_message_id")] attribute to the variant.
You can also add a custom code to the error by adding the #[error(code = 400)] attribute to the variant.
The following status are available and return the corresponding status code:

match error_kind {
    "BadRequest" => 400,
    "Unauthorized" => 401,
    "Forbidden" => 403,
    "NotFound" => 404,
    "MethodNotAllowed" => 405,
    "Conflict" => 409,
    "Gone" => 410,
    "PayloadTooLarge" => 413,
    "UnsupportedMediaType" => 415,
    "UnprocessableEntity" => 422,
    "TooManyRequests" => 429,
    "InternalServerError" => 500,
    "NotImplemented" => 501,
    "BadGateway" => 502,
    "ServiceUnavailable" => 503,
    "GatewayTimeout" => 504,
    _ => unreachable!(),
}