use std::fmt;
#[derive(Debug, Clone)]
pub struct AxeneError {
pub status: u16,
pub code: Option<String>,
pub message: String,
}
impl AxeneError {
pub fn new(status: u16, message: impl Into<String>, code: Option<String>) -> Self {
Self {
status,
code,
message: message.into(),
}
}
pub fn transport(message: impl Into<String>) -> Self {
Self {
status: 0,
code: None,
message: message.into(),
}
}
}
impl fmt::Display for AxeneError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.code {
Some(code) => write!(f, "Axene error {} ({}): {}", self.status, code, self.message),
None => write!(f, "Axene error {}: {}", self.status, self.message),
}
}
}
impl std::error::Error for AxeneError {}
pub type Result<T> = std::result::Result<T, AxeneError>;