use thiserror::Error;
#[derive(Debug, Error)]
pub enum MadeOnSolError {
#[error(
"MadeOnSol: apiKey is required and must start with `msk_`. \
Get a free key at https://madeonsol.com/developer"
)]
MissingApiKey,
#[error("MadeOnSol API error ({status}): {message}")]
Api {
status: u16,
message: String,
body: serde_json::Value,
},
#[error("MadeOnSol transport error: {0}")]
Transport(#[from] reqwest::Error),
#[error("MadeOnSol JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("MadeOnSol URL error: {0}")]
Url(#[from] url::ParseError),
}
impl MadeOnSolError {
pub fn status(&self) -> Option<u16> {
match self {
MadeOnSolError::Api { status, .. } => Some(*status),
_ => None,
}
}
pub fn body(&self) -> Option<&serde_json::Value> {
match self {
MadeOnSolError::Api { body, .. } => Some(body),
_ => None,
}
}
}
pub type Result<T> = std::result::Result<T, MadeOnSolError>;