use serde::Deserialize;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum MutationErrorClass {
Validation,
Conflict,
NotFound,
Unauthorized,
Forbidden,
Internal,
TransactionFailed,
Timeout,
RateLimited,
ServiceUnavailable,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[non_exhaustive]
pub enum CascadeErrorCode {
ValidationError,
Conflict,
NotFound,
Unauthorized,
Forbidden,
InternalError,
TransactionFailed,
Timeout,
RateLimited,
ServiceUnavailable,
}
impl MutationErrorClass {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Validation => "validation",
Self::Conflict => "conflict",
Self::NotFound => "not_found",
Self::Unauthorized => "unauthorized",
Self::Forbidden => "forbidden",
Self::Internal => "internal",
Self::TransactionFailed => "transaction_failed",
Self::Timeout => "timeout",
Self::RateLimited => "rate_limited",
Self::ServiceUnavailable => "service_unavailable",
}
}
#[must_use]
pub const fn to_cascade_code(self) -> CascadeErrorCode {
match self {
Self::Validation => CascadeErrorCode::ValidationError,
Self::Conflict => CascadeErrorCode::Conflict,
Self::NotFound => CascadeErrorCode::NotFound,
Self::Unauthorized => CascadeErrorCode::Unauthorized,
Self::Forbidden => CascadeErrorCode::Forbidden,
Self::Internal => CascadeErrorCode::InternalError,
Self::TransactionFailed => CascadeErrorCode::TransactionFailed,
Self::Timeout => CascadeErrorCode::Timeout,
Self::RateLimited => CascadeErrorCode::RateLimited,
Self::ServiceUnavailable => CascadeErrorCode::ServiceUnavailable,
}
}
}