port-sdk 0.1.0

Rust SDK for Port APIs.
Documentation
use reqwest::header::HeaderMap;
use thiserror::Error;

/// Unified error type returned by the Port SDK.
#[derive(Debug, Error)]
pub enum PortError {
    /// Underlying networking or TLS failure surfaced by `reqwest`.
    #[error("http error: {0}")]
    Http(#[from] reqwest::Error),
    /// Errors encountered while parsing or joining URLs.
    #[error("url error: {0}")]
    Url(#[from] url::ParseError),
    /// Non-successful HTTP status codes plus the response body (if any).
    #[error("api error: {status} {message}")]
    Api { status: u16, message: String, headers: HeaderMap },
    /// JSON serialization or deserialization failures.
    #[error("serialization error: {0}")]
    Serde(#[from] serde_json::Error),
    /// Invalid or missing configuration detected at runtime.
    #[error("configuration error: {0}")]
    Configuration(String),
    /// Environment-related failures such as unreadable `.env` files.
    #[error("environment error: {0}")]
    Environment(String),
}

impl PortError {
    pub fn api(status: u16, message: String, headers: HeaderMap) -> Self {
        PortError::Api { status, message, headers }
    }
}