chore: scaffold axum server with in-memory CRUD, auth stub and tracing
This commit is contained in:
33
backend/src/error.rs
Normal file
33
backend/src/error.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use std::fmt;
|
||||
|
||||
use axum::{http::StatusCode, response::IntoResponse};
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum LoftError {
|
||||
LoginFail,
|
||||
FileIdNotFound,
|
||||
}
|
||||
|
||||
impl fmt::Display for LoftError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for LoftError {}
|
||||
|
||||
impl IntoResponse for LoftError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self {
|
||||
Self::LoginFail => {
|
||||
info!("UNAUTHORIZED");
|
||||
StatusCode::UNAUTHORIZED.into_response()
|
||||
}
|
||||
Self::FileIdNotFound => {
|
||||
info!("NOT_FOUND");
|
||||
StatusCode::NOT_FOUND.into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user