1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::fmt;
use std::fmt::{Display, Formatter};

#[cfg(feature = "canister")]
use candid::CandidType;
use serde::Deserialize;

#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "canister", derive(CandidType))]
pub struct ErrorInfo {
    /// Error code
    pub code: u32,
    /// Error message
    pub message: String,
}

impl PartialEq<Self> for ErrorInfo {
    fn eq(&self, other: &Self) -> bool {
        self.code == other.code
    }
}

impl Eq for ErrorInfo {}

impl Display for ErrorInfo {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "{} {}", self.code, self.message)
    }
}