Skip to main content

trade_alerts/
errors.rs

1//! Error handling and logging module for various service interactions.
2
3use std::fmt;
4
5/// Errors related to Supabase service operations.
6#[derive(Debug)]
7pub enum SupabaseError {
8    /// Error during authentication.
9    AuthenticationError(String),
10    /// Error during data insertion.
11    InsertionError(String),
12    /// Error during data update.
13    UpdateError(String),
14    /// Error during data deletion.
15    DeletionError(String),
16    /// Error during data fetching.
17    FetchError(String),
18}
19
20/// Display implementation for `SupabaseError`.
21impl fmt::Display for SupabaseError {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        match self {
24            SupabaseError::AuthenticationError(msg) => write!(f, "Authentication Error: {}", msg),
25            SupabaseError::InsertionError(msg) => write!(f, "Insertion Error: {}", msg),
26            SupabaseError::UpdateError(msg) => write!(f, "Update Error: {}", msg),
27            SupabaseError::DeletionError(msg) => write!(f, "Deletion Error: {}", msg),
28            SupabaseError::FetchError(msg) => write!(f, "Fetch Error: {}", msg),
29        }
30    }
31}
32
33/// Error trait implementation for `SupabaseError`.
34impl std::error::Error for SupabaseError {}
35
36/// Errors related to table configuration operations.
37#[derive(Debug)]
38pub enum TableConfigError {
39    /// Invalid configuration.
40    InvalidConfiguration(String),
41    /// Configuration file not found.
42    FileNotFound(String),
43    /// Error parsing configuration file.
44    ParseError(String),
45}
46
47/// Display implementation for `TableConfigError`.
48impl fmt::Display for TableConfigError {
49    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50        match self {
51            TableConfigError::InvalidConfiguration(msg) => write!(f, "Invalid Configuration: {}", msg),
52            TableConfigError::FileNotFound(msg) => write!(f, "File Not Found: {}", msg),
53            TableConfigError::ParseError(msg) => write!(f, "Parse Error: {}", msg),
54        }
55    }
56}
57
58/// Error trait implementation for `TableConfigError`.
59impl std::error::Error for TableConfigError {}
60
61/// Errors related to Xylex API interactions.
62#[derive(Debug)]
63pub enum XylexApiError {
64    /// Network connectivity issues.
65    NetworkError(String),
66    /// Invalid symbol provided.
67    InvalidSymbol(String),
68    /// Unexpected error occurred.
69    UnexpectedError(String),
70    /// Authentication error due to environment settings.
71    EnvAuthenticationError(String),
72}
73
74/// Display implementation for `XylexApiError`.
75impl fmt::Display for XylexApiError {
76    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77        match self {
78            XylexApiError::NetworkError(msg) => write!(f, "Network error: {}", msg),
79            XylexApiError::InvalidSymbol(symbol) => write!(f, "Invalid symbol provided: {}", symbol),
80            XylexApiError::UnexpectedError(info) => write!(f, "An unexpected error occurred: {}", info),
81            XylexApiError::EnvAuthenticationError(msg) => write!(f, "Environment-based authentication error: {}", msg),
82        }
83    }
84}
85
86/// Error trait implementation for `XylexApiError`.
87impl std::error::Error for XylexApiError {}