cryptomarket/api/response/
error.rs1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3#[derive(Serialize, Deserialize, Debug, Clone, Hash)]
4pub struct ErrorData {
5 code: i32,
6 message: String,
7 description: Option<String>,
8}
9#[derive(Serialize, Deserialize, Debug, Clone, Hash, Error)]
10pub struct Error {
11 pub error: ErrorData,
12 pub id: Option<i64>,
13}
14
15impl Error {
16 pub fn code(&self) -> i32 {
17 self.error.code
18 }
19}
20
21impl std::fmt::Display for Error {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 write!(f, "{}. ", self.error.message)?;
24 if let Some(extra) = &self.error.description {
25 write!(f, "{}. ", extra)?;
26 }
27 write!(f, "code: {}", self.error.code)?;
28 Ok(())
29 }
30}