Initial commit

This commit is contained in:
Silas Brack 2026-03-07 09:53:12 +01:00
commit 8d32777f9f
8 changed files with 2790 additions and 0 deletions

45
src/error.rs Normal file
View file

@ -0,0 +1,45 @@
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
#[derive(Debug)]
pub enum AppError {
NotFound,
Db(rusqlite::Error),
WriterDead,
WriterDroppedReply,
VolumeError(String),
NoHealthyVolume,
}
impl From<rusqlite::Error> for AppError {
fn from(e: rusqlite::Error) -> Self {
match e {
rusqlite::Error::QueryReturnedNoRows => AppError::NotFound,
other => AppError::Db(other),
}
}
}
impl std::fmt::Display for AppError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AppError::NotFound => write!(f, "not found"),
AppError::Db(e) => write!(f, "database error: {e}"),
AppError::WriterDead => write!(f, "writer dead"),
AppError::WriterDroppedReply => write!(f, "writer dropped reply"),
AppError::VolumeError(msg) => write!(f, "volume error: {msg}"),
AppError::NoHealthyVolume => write!(f, "no healthy volume available"),
}
}
}
impl IntoResponse for AppError {
fn into_response(self) -> Response {
let (status, msg) = match &self {
AppError::NotFound => (StatusCode::NOT_FOUND, self.to_string()),
AppError::NoHealthyVolume => (StatusCode::SERVICE_UNAVAILABLE, self.to_string()),
_ => (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()),
};
(status, msg).into_response()
}
}