server_common/error/
db.rs1use axum::{
2 http::StatusCode,
3 response::{IntoResponse, Response},
4};
5
6#[derive(Debug)]
8pub enum DbError {
9 ConnectError,
10 QueryError,
11 PoolIsNotExistError,
12}
13
14impl IntoResponse for DbError {
16 fn into_response(self) -> Response {
17 let (status, error_message) = match self {
18 DbError::ConnectError => (
19 StatusCode::INTERNAL_SERVER_ERROR,
20 "Failed to connect to database",
21 ),
22 DbError::QueryError => (StatusCode::INTERNAL_SERVER_ERROR, "Database query failed"),
23 DbError::PoolIsNotExistError => (
24 StatusCode::INTERNAL_SERVER_ERROR,
25 "The database connection pool does not exist",
26 ),
27 };
28
29 (status, error_message).into_response()
30 }
31}