pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("missing FMP API key; set FMP_API_KEY or pass --api-key")]
MissingApiKey,
#[error("invalid FMP base URL: {0}")]
InvalidBaseUrl(String),
#[error("missing required CLI argument: {0}")]
MissingArgument(&'static str),
#[error("FMP API request failed with HTTP {status}: {message}")]
Api {
status: u16,
message: String,
},
#[error("HTTP request failed: {0}")]
Http(reqwest::Error),
#[error("failed to render JSON output: {0}")]
Json(#[from] serde_json::Error),
}
impl From<reqwest::Error> for Error {
fn from(error: reqwest::Error) -> Self {
Self::Http(error.without_url())
}
}
impl Error {
#[must_use]
pub const fn kind(&self) -> &'static str {
match self {
Self::MissingApiKey => "missing_api_key",
Self::InvalidBaseUrl(_) => "invalid_base_url",
Self::MissingArgument(_) => "missing_argument",
Self::Api { .. } => "api_error",
Self::Http(_) => "http_error",
Self::Json(_) => "json_error",
}
}
}