elif_core/
error.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum ElifError {
7    #[error("IO error: {0}")]
8    Io(#[from] std::io::Error),
9    
10    #[error("YAML parsing error: {0}")]
11    Yaml(#[from] serde_yaml::Error),
12    
13    #[error("JSON parsing error: {0}")]
14    Json(#[from] serde_json::Error),
15    
16    #[error("Validation error: {0}")]
17    Validation(String),
18    
19    #[error("Codegen error: {0}")]
20    Codegen(String),
21    
22    #[error("Template error: {0}")]
23    Template(String),
24    
25    #[error("API error: {code} - {message}")]
26    Api { code: String, message: String, hint: Option<String> },
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct ErrorDefinition {
31    pub code: String,
32    pub http: u16,
33    pub message: String,
34    pub hint: String,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct ApiErrorResponse {
39    pub error: ApiError,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct ApiError {
44    pub code: String,
45    pub message: String,
46    pub hint: Option<String>,
47}
48
49impl ApiError {
50    pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
51        Self {
52            code: code.into(),
53            message: message.into(),
54            hint: None,
55        }
56    }
57    
58    pub fn with_hint(mut self, hint: impl Into<String>) -> Self {
59        self.hint = Some(hint.into());
60        self
61    }
62}
63
64pub type ErrorCatalog = HashMap<String, ErrorDefinition>;