error handling

This commit is contained in:
2025-10-29 11:14:19 +01:00
parent ac27a9ab36
commit ee8955574f
10 changed files with 102 additions and 36 deletions
+32
View File
@@ -0,0 +1,32 @@
use diesel::result::Error as DieselError;
use crate::error::{AppError, AppResult};
pub trait DbResultExt<T> {
fn db_context(self, context: &'static str) -> AppResult<T>;
}
impl<T> DbResultExt<T> for Result<T, DieselError> {
fn db_context(self, context: &'static str) -> AppResult<T> {
self.map_err(|err| match err {
DieselError::NotFound => AppError::not_found(),
other => {
tracing::error!(error = ?other, "{context}");
AppError::internal(context)
}
})
}
}
pub trait StorageResultExt<T> {
fn storage_context(self, context: &'static str) -> AppResult<T>;
}
impl<T> StorageResultExt<T> for Result<T, anyhow::Error> {
fn storage_context(self, context: &'static str) -> AppResult<T> {
self.map_err(|err| {
tracing::error!(error = ?err, "{context}");
AppError::internal(context)
})
}
}
+1
View File
@@ -1,5 +1,6 @@
pub mod bootstrap;
pub mod db;
pub mod error;
pub mod http;
pub mod json;
pub mod storage_paths;