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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use serde::{Deserialize, Serialize};

/// Zebedee Error
#[derive(thiserror::Error, Debug)]
pub enum ZebedeeError {
    /// Error from reqwest crate which is used to make HTTP requests
    #[error("{0}")]
    InvalidRequest(#[from] reqwest::Error),
    /// Serde json Errors when parsing
    #[error("Unable to parse json: {0}")]
    InvalidJson(#[from] serde_json::Error),
    /// Serde json Errors when parsing
    #[error("{0}")]
    Validate(#[from] validator::ValidationErrors),
    /// Error messages from Zebedee REST API
    #[error("{0:?}")]
    Api(ApiError),
    /// Internal Error messages
    #[error("{0:?}")]
    Msg(ErrorMsg),
}

/// Zebedee Rest API error message
#[derive(Debug, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct ApiError {
    /// Error message
    pub message: String,
    /// Status of API call
    pub success: bool,
}

/// General Error messages
#[derive(thiserror::Error, Debug)]
pub enum ErrorMsg {
    /// Bad Gamertag Payment format
    #[error("Bad Gamertag Payment format {0}")]
    BadGamerTagFormat(String),
    /// Bad payload data
    #[error("Bad payload data {0}")]
    BadPayloadData(String),
    /// Bad LN Address
    #[error("Bad LN Address {0}, ValidationError {1}")]
    BadLnAddress(String, String),
}

impl From<ErrorMsg> for ZebedeeError {
    fn from(value: ErrorMsg) -> Self {
        ZebedeeError::Msg(value)
    }
}

impl From<ApiError> for ZebedeeError {
    fn from(value: ApiError) -> Self {
        ZebedeeError::Api(value)
    }
}