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
use std::convert::From;
use std::fmt::{self, Display, Formatter};
use reqwest::Error;

#[derive(Debug, Eq, PartialEq)]
pub struct FhttpError {
    pub msg: String,
}

impl FhttpError {
    pub fn new<T: Into<String>>(msg: T) -> Self {
        FhttpError {
            msg: msg.into(),
        }
    }
}

impl Display for FhttpError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::result::Result<(), fmt::Error> {
        write!(f, "{}", self.msg)
    }
}

impl std::error::Error for FhttpError {}

impl From<reqwest::Error> for FhttpError {
    fn from(e: Error) -> Self {
        FhttpError::new(format!("{}", e))
    }
}

pub type Result<T> = std::result::Result<T, FhttpError>;