Skip to main content

port_sdk/
error.rs

1use reqwest::header::HeaderMap;
2use thiserror::Error;
3
4/// Unified error type returned by the Port SDK.
5#[derive(Debug, Error)]
6pub enum PortError {
7    /// Underlying networking or TLS failure surfaced by `reqwest`.
8    #[error("http error: {0}")]
9    Http(#[from] reqwest::Error),
10    /// Errors encountered while parsing or joining URLs.
11    #[error("url error: {0}")]
12    Url(#[from] url::ParseError),
13    /// Non-successful HTTP status codes plus the response body (if any).
14    #[error("api error: {status} {message}")]
15    Api { status: u16, message: String, headers: HeaderMap },
16    /// JSON serialization or deserialization failures.
17    #[error("serialization error: {0}")]
18    Serde(#[from] serde_json::Error),
19    /// Invalid or missing configuration detected at runtime.
20    #[error("configuration error: {0}")]
21    Configuration(String),
22    /// Environment-related failures such as unreadable `.env` files.
23    #[error("environment error: {0}")]
24    Environment(String),
25}
26
27impl PortError {
28    pub fn api(status: u16, message: String, headers: HeaderMap) -> Self {
29        PortError::Api { status, message, headers }
30    }
31}