use crate::ValidateResponse;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("API key is required. Get one at https://www.proofgate.xyz/dashboard")]
MissingApiKey,
#[error("Invalid API key format. Keys start with \"pg_\"")]
InvalidApiKey,
#[error("Validation failed: {reason}")]
ValidationFailed {
reason: String,
result: Box<ValidateResponse>,
},
#[error("API error ({status}): {message}")]
ApiError {
status: u16,
message: String,
},
#[error("Network error: {0}")]
NetworkError(#[from] reqwest::Error),
#[error("Request timeout")]
Timeout,
#[error("JSON parse error: {0}")]
ParseError(#[from] serde_json::Error),
}
impl Error {
pub fn code(&self) -> &'static str {
match self {
Error::MissingApiKey => "MISSING_API_KEY",
Error::InvalidApiKey => "INVALID_API_KEY",
Error::ValidationFailed { .. } => "VALIDATION_FAILED",
Error::ApiError { .. } => "API_ERROR",
Error::NetworkError(_) => "NETWORK_ERROR",
Error::Timeout => "TIMEOUT",
Error::ParseError(_) => "PARSE_ERROR",
}
}
}