use serde::{Deserialize, Serialize};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, Deserialize, Serialize, thiserror::Error)]
#[error("{code}: {message}")]
pub struct ApiError {
pub code: String,
pub message: String,
#[serde(skip, default)]
pub http_status: Option<u16>,
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Api(#[from] ApiError),
#[error("http transport error: {0}")]
Http(#[from] reqwest::Error),
#[error("invalid url: {0}")]
InvalidUrl(String),
#[error("failed to decode response: {0}")]
Decode(#[from] serde_json::Error),
#[error("response missing data field")]
MissingData,
}
impl ApiError {
pub(crate) fn with_http_status(mut self, status: u16) -> Self {
if self.http_status.is_none() {
self.http_status = Some(status);
}
self
}
}