1
0
mirror of https://github.com/actix/examples synced 2025-02-20 16:30:32 +01:00
2024-07-07 02:01:13 +01:00

26 lines
738 B
Rust

use actix_web::{HttpResponse, ResponseError};
use deadpool_postgres::PoolError;
use derive_more::{Display, Error, From};
use tokio_pg_mapper::Error as PGMError;
use tokio_postgres::error::Error as PGError;
#[derive(Debug, Display, Error, From)]
pub enum MyError {
NotFound,
PGError(PGError),
PGMError(PGMError),
PoolError(PoolError),
}
impl ResponseError for MyError {
fn error_response(&self) -> HttpResponse {
match *self {
MyError::NotFound => HttpResponse::NotFound().finish(),
MyError::PoolError(ref err) => {
HttpResponse::InternalServerError().body(err.to_string())
}
_ => HttpResponse::InternalServerError().finish(),
}
}
}