//! Error type returned by every SDK call.

/// Everything that can go wrong calling fin-proxy.
#[derive(Debug, thiserror::Error)]
pub enum SdkError {
    /// Connection, TLS, or timeout error from the HTTP layer.
    #[error("transport error: {0}")]
    Transport(#[from] reqwest::Error),

    /// The server returned a non-2xx status, or a 2xx with `success: false`.
    /// `message` carries fin-proxy's `error` field when present.
    #[error("api error (status {code}): {}", message.as_deref().unwrap_or("<no message>"))]
    Status { code: u16, message: Option<String> },

    /// A 2xx response body could not be deserialized into the expected type.
    #[error("decode error: {0}")]
    Decode(serde_json::Error),

    /// A 2xx response had `success: true` but no `data`.
    #[error("response had success=true but no data")]
    EmptyData,

    /// The configured base URL could not be parsed/joined.
    #[error("invalid base url: {0}")]
    InvalidBaseUrl(#[from] url::ParseError),
}
