Better error logging

main
Joey Hines 2024-02-22 19:13:57 -07:00
parent 1b1f6a3eee
commit 6919b2b6f0
No known key found for this signature in database
GPG Key ID: 995E531F7A569DDB
2 changed files with 7 additions and 8 deletions

2
Cargo.lock generated
View File

@ -1143,7 +1143,7 @@ dependencies = [
[[package]]
name = "pic_ox"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"async-trait",
"axum",

View File

@ -60,6 +60,7 @@ where
}
#[allow(dead_code)]
#[derive(Debug)]
pub enum PicOxError {
StoreError(StoreError),
DbError(j_db::error::JDbError),
@ -88,18 +89,16 @@ pub struct ErrorResponse {
impl IntoResponse for PicOxError {
fn into_response(self) -> axum::response::Response {
error!("API Error: {:?}", self);
let (status, message) = match self {
PicOxError::StoreError(err) => match err {
StoreError::InvalidFile => (StatusCode::BAD_REQUEST, err.to_string()),
StoreError::OutOfStorage => (StatusCode::INSUFFICIENT_STORAGE, err.to_string()),
StoreError::ImageTooBig => (StatusCode::UNAUTHORIZED, err.to_string()),
StoreError::IOError(e) => {
error!("IO error occurred handling request {}", e);
(
StatusCode::INTERNAL_SERVER_ERROR,
"IO Error Has Occurred!".to_string(),
)
}
StoreError::IOError(_) => (
StatusCode::INTERNAL_SERVER_ERROR,
"IO Error Has Occurred!".to_string(),
),
},
PicOxError::DbError(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()),
PicOxError::AlbumNotFound => (