1pub type Result<T> = std::result::Result<T, Error>;
2
3#[derive(thiserror::Error, Debug)]
4pub enum Error {
5 #[error(transparent)]
6 Io(#[from] std::io::Error),
7 #[error(transparent)]
8 Env(#[from] shellexpand::LookupError<std::env::VarError>),
9 #[error("Api error: {0}")]
10 Internal(String),
11 #[error("Bad request: {0}")]
12 BadRequest(String),
13 #[error("Not found: {0}")]
14 NotFound(String),
15}
16
17impl axum::response::IntoResponse for Error {
18 fn into_response(self) -> axum::response::Response {
19 let (status, message) = match &self {
20 Error::NotFound(msg) => (axum::http::StatusCode::NOT_FOUND, msg.clone()),
21 Error::BadRequest(msg) => (axum::http::StatusCode::BAD_REQUEST, msg.clone()),
22 _ => (axum::http::StatusCode::INTERNAL_SERVER_ERROR, self.to_string()),
23 };
24 (status, axum::Json(stately::ApiError::new(message, status))).into_response()
25 }
26}