x_mcp_server/
error.rs

1//! Error types for X MCP Server
2
3use thiserror::Error;
4
5/// Result type alias for X operations
6pub type XResult<T> = Result<T, XError>;
7
8/// Error types for X API operations
9#[derive(Error, Debug)]
10pub enum XError {
11    /// HTTP request errors
12    #[error("HTTP request failed: {0}")]
13    Http(#[from] reqwest::Error),
14
15    /// JSON serialization/deserialization errors
16    #[error("JSON error: {0}")]
17    Json(#[from] serde_json::Error),
18
19    /// IO errors
20    #[error("IO error: {0}")]
21    Io(#[from] std::io::Error),
22
23    /// RMCP server initialization errors
24    #[error("Server initialization error: {0}")]
25    ServerInit(String),
26
27    /// Join errors from tokio
28    #[error("Join error: {0}")]
29    Join(#[from] tokio::task::JoinError),
30
31    /// Authentication errors
32    #[error("Authentication error: {0}")]
33    Auth(String),
34
35    /// API errors from X
36    #[error("X API error: {status} - {message}")]
37    Api { status: u16, message: String },
38
39    /// Configuration errors
40    #[error("Configuration error: {0}")]
41    Config(String),
42
43    /// Generic errors
44    #[error("Error: {0}")]
45    Generic(String),
46}
47
48impl From<anyhow::Error> for XError {
49    fn from(err: anyhow::Error) -> Self {
50        XError::Generic(err.to_string())
51    }
52}
53
54impl<T> From<rmcp::service::ServerInitializeError<T>> for XError
55where
56    T: std::fmt::Display,
57{
58    fn from(err: rmcp::service::ServerInitializeError<T>) -> Self {
59        XError::ServerInit(err.to_string())
60    }
61}