Skip to main content

server_common/error/
config.rs

1use axum::{
2    http::StatusCode,
3    response::{IntoResponse, Response},
4};
5
6// 定义配置错误类型
7#[derive(Debug)]
8pub enum ConfigError {
9    DatabaseError,
10    RedisError,
11    PathError,
12    NotExistError,
13}
14
15// 为 DatabaseError 实现 IntoResponse
16impl IntoResponse for ConfigError {
17    fn into_response(self) -> Response {
18        let (status, error_message) = match self {
19            ConfigError::DatabaseError => {
20                (StatusCode::INTERNAL_SERVER_ERROR, "database config error")
21            }
22            ConfigError::RedisError => (StatusCode::INTERNAL_SERVER_ERROR, "redis config error"),
23            ConfigError::PathError => (StatusCode::INTERNAL_SERVER_ERROR, "config path error"),
24            ConfigError::NotExistError => {
25                (StatusCode::INTERNAL_SERVER_ERROR, "config not exist error")
26            }
27        };
28
29        (status, error_message).into_response()
30    }
31}