use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct FieldError {
#[serde(default)]
pub field: String,
#[serde(default)]
pub message: String,
#[serde(default)]
pub code: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ErrorBody {
#[serde(rename = "type", default)]
pub error_type: String,
#[serde(default)]
pub title: String,
#[serde(default)]
pub status: u16,
#[serde(default)]
pub detail: String,
#[serde(default)]
pub request_id: String,
#[serde(default)]
pub fields: Vec<FieldError>,
}
impl std::fmt::Display for ErrorBody {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if !self.detail.is_empty() {
write!(f, "{}", self.detail)
} else if !self.title.is_empty() {
write!(f, "{}", self.title)
} else {
write!(f, "HTTP {}", self.status)
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum VynFiError {
#[error("authentication error: {0}")]
Authentication(Box<ErrorBody>),
#[error("insufficient credits: {0}")]
InsufficientCredits(Box<ErrorBody>),
#[error("forbidden: {0}")]
Forbidden(Box<ErrorBody>),
#[error("not found: {0}")]
NotFound(Box<ErrorBody>),
#[error("conflict: {0}")]
Conflict(Box<ErrorBody>),
#[error("validation error: {0}")]
Validation(Box<ErrorBody>),
#[error("rate limited: {0}")]
RateLimit(Box<ErrorBody>),
#[error("server error: {0}")]
Server(Box<ErrorBody>),
#[error("http error: {0}")]
Http(#[from] reqwest::Error),
#[error("deserialization error: {0}")]
Deserialize(#[from] serde_json::Error),
#[error("{0}")]
Config(String),
}