Skip to main content

ltfi_wsap/
error.rs

1use std::fmt;
2
3/// Error types for the LTFI-WSAP SDK
4#[derive(Debug)]
5pub enum Error {
6    /// Authentication error (missing or invalid API key)
7    Authentication(String),
8    /// Network error (connection issues)
9    Network(String),
10    /// API error (HTTP status code and message)
11    Api(u16, String),
12    /// JSON parsing error
13    Parse(String),
14    /// Validation error
15    Validation(String),
16}
17
18impl fmt::Display for Error {
19    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20        match self {
21            Error::Authentication(msg) => write!(f, "Authentication error: {}", msg),
22            Error::Network(msg) => write!(f, "Network error: {}", msg),
23            Error::Api(code, msg) => write!(f, "API error ({}): {}", code, msg),
24            Error::Parse(msg) => write!(f, "Parse error: {}", msg),
25            Error::Validation(msg) => write!(f, "Validation error: {}", msg),
26        }
27    }
28}
29
30impl std::error::Error for Error {}
31
32/// Result type alias for the SDK
33pub type Result<T> = std::result::Result<T, Error>;