turbomcp_openapi/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, OpenApiError>;
7
8#[derive(Debug, Error)]
10pub enum OpenApiError {
11 #[error("failed to fetch OpenAPI spec: {0}")]
13 FetchError(#[from] reqwest::Error),
14
15 #[error("failed to parse OpenAPI spec: {0}")]
17 ParseError(String),
18
19 #[error("failed to read OpenAPI spec file: {0}")]
21 IoError(#[from] std::io::Error),
22
23 #[error("invalid URL: {0}")]
25 InvalidUrl(#[from] url::ParseError),
26
27 #[error("invalid regex pattern: {0}")]
29 InvalidPattern(#[from] regex::Error),
30
31 #[error("API call failed: {0}")]
33 ApiError(String),
34
35 #[error("missing required parameter: {0}")]
37 MissingParameter(String),
38
39 #[error("invalid parameter value for '{0}': {1}")]
41 InvalidParameter(String, String),
42
43 #[error("operation not found: {0}")]
45 OperationNotFound(String),
46
47 #[error("base URL not configured - call with_base_url() before making API calls")]
49 NoBaseUrl,
50
51 #[error("SSRF protection: {0}")]
53 SsrfBlocked(String),
54
55 #[error("request timed out after {0} seconds")]
57 Timeout(u64),
58}
59
60impl From<serde_json::Error> for OpenApiError {
61 fn from(err: serde_json::Error) -> Self {
62 Self::ParseError(err.to_string())
63 }
64}
65
66impl From<serde_yaml::Error> for OpenApiError {
67 fn from(err: serde_yaml::Error) -> Self {
68 Self::ParseError(err.to_string())
69 }
70}