fix: implement Display trait for ServiceError enum

This commit is contained in:
GW_MC
2025-12-15 15:50:43 +08:00
parent b17d111c5d
commit 1233f3b736

View File

@@ -15,6 +15,20 @@ impl From<Box<dyn std::error::Error + Send + Sync + 'static>> for ServiceError {
} }
} }
impl std::fmt::Display for ServiceError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ServiceError::NotFound(msg) => write!(f, "Not Found: {}", msg),
ServiceError::DatabaseError(msg) => write!(f, "Database Error: {}", msg),
ServiceError::Unauthorized(msg) => write!(f, "Unauthorized: {}", msg),
ServiceError::InternalError(msg) => write!(f, "Internal Error: {}", msg),
ServiceError::BadRequest(msg) => write!(f, "Bad Request: {}", msg),
}
}
}
impl std::error::Error for ServiceError {}
impl From<DbErr> for ServiceError { impl From<DbErr> for ServiceError {
fn from(err: DbErr) -> Self { fn from(err: DbErr) -> Self {
match err { match err {