flutterwave_v3_models/
errors.rs

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
use std::fmt::Display;

#[derive(Debug, thiserror::Error)]
pub enum FWaveError {
    SerDe(serde_json::Error),
    Request(reqwest::Error),
    RequestValidation(validator::ValidationErrors),
}

impl From<reqwest::Error> for FWaveError {
    fn from(value: reqwest::Error) -> Self {
        FWaveError::Request(value)
    }
}

impl From<validator::ValidationErrors> for FWaveError {
    fn from(value: validator::ValidationErrors) -> Self {
        FWaveError::RequestValidation(value)
    }
}

impl From<serde_json::Error> for FWaveError {
    fn from(value: serde_json::Error) -> Self {
        FWaveError::SerDe(value)
    }
}

impl Display for FWaveError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            FWaveError::SerDe(error) => f.write_str(&error.to_string()),
            FWaveError::Request(error) => f.write_str(&error.to_string()),
            FWaveError::RequestValidation(validation_errors) => {
                f.write_str(&validation_errors.to_string())
            }
        }
    }
}