2023-05-08 09:48:11 +00:00
|
|
|
//! Errors.
|
|
|
|
|
|
|
|
use axum::{
|
|
|
|
http::StatusCode,
|
|
|
|
response::{IntoResponse, Response},
|
|
|
|
};
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum Error {
|
2023-05-08 16:05:43 +00:00
|
|
|
#[error("GitHub API error: {0}")]
|
2023-06-22 18:57:02 +00:00
|
|
|
Api(#[from] gha_cache::api::Error),
|
2023-05-08 09:48:11 +00:00
|
|
|
|
|
|
|
#[error("Not Found")]
|
|
|
|
NotFound,
|
|
|
|
|
|
|
|
#[error("Bad Request")]
|
|
|
|
BadRequest,
|
2023-05-19 08:48:52 +00:00
|
|
|
|
|
|
|
#[error("I/O error: {0}")]
|
2023-06-22 18:57:02 +00:00
|
|
|
Io(#[from] std::io::Error),
|
2023-05-19 08:48:52 +00:00
|
|
|
|
|
|
|
#[error("Failed to upload paths")]
|
|
|
|
FailedToUpload,
|
2023-05-08 09:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoResponse for Error {
|
|
|
|
fn into_response(self) -> Response {
|
|
|
|
let code = match &self {
|
2023-05-08 18:59:57 +00:00
|
|
|
// HACK: HTTP 418 makes Nix throw a visible error but not retry
|
2023-06-22 18:57:02 +00:00
|
|
|
Self::Api(_) => StatusCode::IM_A_TEAPOT,
|
2023-05-08 09:48:11 +00:00
|
|
|
Self::NotFound => StatusCode::NOT_FOUND,
|
|
|
|
Self::BadRequest => StatusCode::BAD_REQUEST,
|
2023-05-19 08:48:52 +00:00
|
|
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
2023-05-08 09:48:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
(code, format!("{}", self)).into_response()
|
|
|
|
}
|
|
|
|
}
|