Files
YANPM/apps/api/src/errors/service_error.rs
2025-12-07 21:33:01 +08:00

26 lines
655 B
Rust

use sea_orm::DbErr;
#[derive(Debug)]
pub enum ServiceError {
NotFound(String),
DatabaseError(String),
Unauthorized(String),
InternalError(String),
BadRequest(String),
}
impl From<Box<dyn std::error::Error + Send + Sync + 'static>> for ServiceError {
fn from(err: Box<dyn std::error::Error + Send + Sync + 'static>) -> Self {
ServiceError::InternalError(err.to_string())
}
}
impl From<DbErr> for ServiceError {
fn from(err: DbErr) -> Self {
match err {
DbErr::RecordNotFound(msg) => ServiceError::NotFound(msg),
_ => ServiceError::DatabaseError(err.to_string()),
}
}
}