meilisearch_api_client/
error.rs

1use serde::{Deserialize, Serialize};
2use actix_web::http::StatusCode;
3
4#[derive(Debug, Serialize, Deserialize)]
5pub struct ResponseBody<T> {
6    pub code: u32,
7    pub message: String,
8    pub data: T,
9}
10
11impl<T> ResponseBody<T> {
12    pub fn new(code: u32, message: &str, data: T) -> ResponseBody<T> {
13        ResponseBody {
14            code: code,
15            message: message.to_string(),
16            data,
17        }
18    }
19}
20
21#[derive(Debug)]
22pub struct ServiceError {
23    pub http_status: StatusCode,
24    pub body: ResponseBody<String>,
25}
26
27impl ServiceError {
28    pub fn new(http_status: StatusCode, message: String) -> ServiceError {
29        ServiceError {
30            http_status,
31            body: ResponseBody {
32                code: http_status.as_u16() as u32,
33                message,
34                data: String::new(),
35            }
36        }
37    }
38}
39