use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ErrorCategory {
ClientError,
AuthError,
ServerError,
RateLimitError,
ValidationError,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ErrorContext {
pub file: Option<String>,
pub line: Option<u32>,
pub function: Option<String>,
pub extra: HashMap<String, String>,
}
impl ErrorContext {
pub fn new() -> Self {
Self {
file: None,
line: None,
function: None,
extra: HashMap::new(),
}
}
pub fn current() -> Self {
Self {
file: Some(file!().to_string()),
line: Some(line!()),
function: Some(std::any::type_name::<()>().to_string()),
extra: HashMap::new(),
}
}
pub fn with_extra(mut self, key: String, value: String) -> Self {
self.extra.insert(key, value);
self
}
}
impl Default for ErrorContext {
fn default() -> Self {
Self::new()
}
}