surrealpatch/lib/examples/actix/src/error.rs
2022-12-30 08:23:19 +00:00

23 lines
446 B
Rust

use actix_web::{HttpResponse, ResponseError};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("database error")]
Db,
}
impl ResponseError for Error {
fn error_response(&self) -> HttpResponse {
match self {
Error::Db => HttpResponse::InternalServerError().body(self.to_string()),
}
}
}
impl From<surrealdb::Error> for Error {
fn from(error: surrealdb::Error) -> Self {
eprintln!("{error}");
Self::Db
}
}