1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("API key not found. Please set the XIAOMI_API_KEY environment variable.")]
13 MissingApiKey,
14
15 #[error("HTTP request failed: {0}")]
17 HttpError(#[from] reqwest::Error),
18
19 #[error("JSON error: {0}")]
21 JsonError(#[from] serde_json::Error),
22
23 #[error("API error: {message} (status: {status})")]
25 ApiError {
26 status: u16,
28 message: String,
30 },
31
32 #[error("Stream parsing error: {0}")]
34 StreamError(String),
35
36 #[error("Invalid parameter: {0}")]
38 InvalidParameter(String),
39
40 #[error("Invalid response: {0}")]
42 InvalidResponse(String),
43
44 #[error("IO error: {0}")]
46 IoError(#[from] std::io::Error),
47}
48
49impl Error {
50 pub fn api_error(status: u16, message: impl Into<String>) -> Self {
52 Error::ApiError {
53 status,
54 message: message.into(),
55 }
56 }
57}