fistinc_errors/
api.rs

1use std::fmt::{Formatter};
2use crate::CommonError;
3
4#[derive(Debug)]
5pub struct ApiError(CommonError);
6
7impl From<CommonError> for ApiError {
8    fn from(error: CommonError) -> Self {
9        Self(error)
10    }
11}
12
13impl From<email_address::Error> for ApiError {
14    fn from(_: email_address::Error) -> Self {
15        Self(
16            CommonError {
17                message: "Wrong Email".to_string(),
18                code: 400,
19            }
20        )
21    }
22}
23
24impl std::fmt::Display for ApiError {
25    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
26        write!(f, "{}", self.0)
27    }
28}
29
30impl actix_web::ResponseError for ApiError {
31    fn error_response(&self) -> actix_http::Response {
32        actix_web::HttpResponse::BadRequest().json(&self.0)
33    }
34}
35
36pub type ApiResult<T> = Result<T, ApiError>;