#[derive(ServerlessError)]
{
// Attributes available to this derive:
#[error]
}
Expand description
Derive macro for error types that implement IntoErrorCode.
§Example
ⓘ
use server_less::ServerlessError;
#[derive(ServerlessError)]
enum MyError {
#[error(code = NotFound, message = "User not found")]
UserNotFound,
#[error(code = 400)] // HTTP status also works
InvalidInput(String),
// Code inferred from variant name
Unauthorized,
}This generates:
impl IntoErrorCode for MyErrorimpl Display for MyErrorimpl Error for MyError
§Attributes
#[error(code = X)]- Set error code (ErrorCode variant or HTTP status)#[error(message = "...")]- Set custom message
Without attributes, the error code is inferred from the variant name.