zesty_api/error.rs
1//
2// Copyright 2023 Zesty Tech Ltd. All rights reserved.
3// Use is subject to license terms.
4//
5
6use serde_json as json;
7use thiserror::Error;
8
9use super::*;
10
11#[derive(Debug, Error, Serialize, Deserialize)]
12#[error("{message}")]
13pub struct Error {
14 #[serde(with = "http_serde::status_code")]
15 pub status: http::StatusCode,
16 pub message: String,
17}
18
19impl From<json::Error> for Error {
20 fn from(error: json::Error) -> Self {
21 let status = http::StatusCode::INTERNAL_SERVER_ERROR;
22 let message = error.to_string();
23 Self { status, message }
24 }
25}