use reqwest::StatusCode;
use thiserror::Error;
use crate::types::ValidationError;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum TreetopError {
#[error("HTTP transport error: {0}")]
Transport(#[from] reqwest::Error),
#[error("API error (HTTP {status}): {message}")]
Api {
status: StatusCode,
message: String,
},
#[error("Response deserialization error: {0}")]
Deserialization(#[from] serde_json::Error),
#[error("Request serialization error: {0}")]
Serialization(#[source] serde_json::Error),
#[error("Request validation error: {0}")]
Validation(#[from] ValidationError),
#[error("Invalid URL: {0}")]
InvalidUrl(#[from] url::ParseError),
#[error("Client configuration error: {0}")]
Configuration(String),
#[error("Response body exceeds the configured limit of {limit} bytes")]
ResponseTooLarge {
limit: usize,
},
#[error("Request body exceeds the configured limit of {limit} bytes")]
RequestTooLarge {
limit: usize,
},
#[error("Successful text response is not valid UTF-8")]
InvalidTextResponse,
#[error("Invalid API response: {0}")]
InvalidResponse(String),
#[error("Authorization evaluation failed: {0}")]
Evaluation(String),
}
pub type Result<T> = std::result::Result<T, TreetopError>;