use std::fmt;
#[derive(Debug)]
pub enum TrustonError {
Http(reqwest::Error),
ServerError {
status: u16,
message: String,
},
InferenceError(String),
ParseError(String),
}
impl fmt::Display for TrustonError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TrustonError::Http(e) => write!(f, "HTTP error: {}", e),
TrustonError::ServerError { status, message } => {
write!(f, "Server error {}: {}", status, message)
}
TrustonError::InferenceError(msg) => write!(f, "Inference error: {}", msg),
TrustonError::ParseError(msg) => write!(f, "Parse error: {}", msg),
}
}
}
impl From<reqwest::Error> for TrustonError {
fn from(e: reqwest::Error) -> Self {
TrustonError::Http(e)
}
}
impl std::error::Error for TrustonError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
TrustonError::Http(e) => Some(e),
_ => None,
}
}
}