use thiserror::Error;
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum ReflectError {
#[error("reflection JSON parse failed: {message}")]
InvalidJson {
raw: String,
message: String,
},
#[error("reflection schema validation failed: {message}")]
InvalidSchema {
raw: String,
message: String,
},
#[error("reflection admission failed: {message}")]
AdmissionRejected {
raw: String,
message: String,
},
#[error("reflection authority failed: {message}")]
AuthorityRejected {
raw: String,
message: String,
},
}
impl ReflectError {
#[must_use]
pub fn quarantine_payload(&self) -> &str {
match self {
Self::InvalidJson { raw, .. }
| Self::InvalidSchema { raw, .. }
| Self::AdmissionRejected { raw, .. }
| Self::AuthorityRejected { raw, .. } => raw,
}
}
#[must_use]
pub const fn quarantine_reason(&self) -> &'static str {
match self {
Self::InvalidJson { .. } => "invalid_json",
Self::InvalidSchema { .. } => "invalid_schema",
Self::AdmissionRejected { .. } => "admission_rejected",
Self::AuthorityRejected { .. } => "authority_rejected",
}
}
#[must_use]
pub fn detail(&self) -> &str {
match self {
Self::InvalidJson { message, .. }
| Self::InvalidSchema { message, .. }
| Self::AdmissionRejected { message, .. }
| Self::AuthorityRejected { message, .. } => message,
}
}
}