Skip to main content

semantic_scholar/
error.rs

1use thiserror::Error;
2
3/// Errors from the Semantic Scholar SDK.
4#[derive(Debug, Error)]
5pub enum Error {
6    /// Failed to initialize the HTTP client.
7    #[error("failed to build HTTP client: {0}")]
8    ClientBuild(reqwest::Error),
9
10    /// HTTP transport error during a request.
11    #[error("HTTP request failed for `{endpoint}`: {source}")]
12    Http {
13        endpoint: String,
14        source: reqwest::Error,
15    },
16
17    /// API returned an error response.
18    #[error("API error ({status}) for `{endpoint}`: {message}")]
19    Api {
20        status: u16,
21        endpoint: String,
22        message: String,
23    },
24
25    /// Rate limited by the API (HTTP 429), retries exhausted.
26    #[error("rate limited for `{endpoint}` after {retries} retries")]
27    RateLimited { endpoint: String, retries: u32 },
28
29    /// JSON deserialization failed.
30    #[error("failed to deserialize response from `{endpoint}`: {source}")]
31    Deserialize {
32        endpoint: String,
33        source: serde_json::Error,
34    },
35
36    /// Invalid parameter provided by the caller.
37    #[error("invalid parameter: {0}")]
38    InvalidParameter(String),
39}
40
41/// Result type alias for this crate.
42pub type Result<T> = std::result::Result<T, Error>;