use std::fmt; use axum::{http::StatusCode, response::IntoResponse}; use tracing::info; #[derive(Debug, Clone)] pub enum LoftError { LoginFail, RegisterFail, AuthFailNoAuthTokenCookie, AuthFailCtxNotInRequestExt, FileIdNotFound, UndefinedErrorType, } 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 | Self::RegisterFail | Self::AuthFailNoAuthTokenCookie | Self::AuthFailCtxNotInRequestExt => { info!("UNAUTHORIZED"); StatusCode::UNAUTHORIZED.into_response() } Self::FileIdNotFound => { info!("NOT_FOUND"); StatusCode::NOT_FOUND.into_response() } Self::UndefinedErrorType => { info!("INTERNAL_SERVER_ERROR"); StatusCode::INTERNAL_SERVER_ERROR.into_response() } } } }