Skip to main content

turul_mcp_aws_lambda/
error.rs

1//! Error handling for Lambda MCP integration
2
3use thiserror::Error;
4
5/// Result type for Lambda MCP operations
6pub type Result<T> = std::result::Result<T, LambdaError>;
7
8/// Errors that can occur during Lambda MCP server operations
9#[derive(Error, Debug)]
10pub enum LambdaError {
11    /// Type conversion error between lambda_http and hyper types
12    #[error("Type conversion failed: {0}")]
13    TypeConversion(String),
14
15    /// HTTP error during request processing
16    #[error("HTTP error: {0}")]
17    Http(#[from] http::Error),
18
19    /// Hyper error during request processing
20    #[error("Hyper error: {0}")]
21    Hyper(#[from] hyper::Error),
22
23    /// Lambda HTTP error
24    #[error("Lambda HTTP error: {0}")]
25    LambdaHttp(#[from] lambda_http::Error),
26
27    /// Session storage error
28    #[error("Session storage error: {0}")]
29    SessionStorage(String),
30
31    /// MCP framework error
32    #[error("MCP framework error: {0}")]
33    McpFramework(String),
34
35    /// JSON serialization/deserialization error
36    #[error("JSON error: {0}")]
37    Json(#[from] serde_json::Error),
38
39    /// Body processing error
40    #[error("Body processing error: {0}")]
41    Body(String),
42
43    /// CORS configuration error
44    #[cfg(feature = "cors")]
45    #[error("CORS error: {0}")]
46    Cors(String),
47
48    /// SSE streaming error
49    #[cfg(feature = "sse")]
50    #[error("SSE streaming error: {0}")]
51    Sse(String),
52
53    /// Configuration error
54    #[error("Configuration error: {0}")]
55    Configuration(String),
56
57    /// Session management error
58    #[error("Session error: {0}")]
59    Session(String),
60}
61
62impl From<turul_http_mcp_server::HttpMcpError> for LambdaError {
63    fn from(err: turul_http_mcp_server::HttpMcpError) -> Self {
64        LambdaError::McpFramework(err.to_string())
65    }
66}
67
68impl From<turul_mcp_session_storage::SessionStorageError> for LambdaError {
69    fn from(err: turul_mcp_session_storage::SessionStorageError) -> Self {
70        LambdaError::SessionStorage(err.to_string())
71    }
72}