use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Spec Error: {0}")]
SpecError(String),
#[cfg(all(not(target_arch = "wasm32"), feature = "api-cli"))]
#[error("Reqwest Error: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("SerdeJson Error: {0}")]
SerdeJson(#[from] serde_json::Error),
#[error("SerdeUrlencoded Error: {0}")]
SerdeUrlencoded(#[from] serde_urlencoded::de::Error),
#[error("IO Error: {0}")]
Io(#[from] std::io::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
impl IntoResponse for Error {
fn into_response(self) -> Response {
match &self {
Error::SerdeUrlencoded(_) => (StatusCode::BAD_REQUEST, self.to_string()).into_response(),
_ => (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()).into_response(),
}
}
}