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