pw_telegram_bot_fork/
errors.rs

1use std::error;
2use std::fmt;
3
4#[derive(Debug)]
5pub struct Error(ErrorKind);
6
7#[derive(Debug)]
8pub(crate) enum ErrorKind {
9    Raw(pw_telegram_bot_raw_fork::Error),
10    Hyper(hyper::Error),
11    Http(hyper::http::Error),
12    Io(std::io::Error),
13    InvalidMultipartFilename,
14}
15
16impl From<pw_telegram_bot_raw_fork::Error> for ErrorKind {
17    fn from(error: pw_telegram_bot_raw_fork::Error) -> Self {
18        ErrorKind::Raw(error)
19    }
20}
21
22impl From<hyper::Error> for ErrorKind {
23    fn from(error: hyper::Error) -> Self {
24        ErrorKind::Hyper(error)
25    }
26}
27
28impl From<hyper::http::Error> for ErrorKind {
29    fn from(error: hyper::http::Error) -> Self {
30        ErrorKind::Http(error)
31    }
32}
33
34impl From<std::io::Error> for ErrorKind {
35    fn from(error: std::io::Error) -> Self {
36        ErrorKind::Io(error)
37    }
38}
39
40impl From<ErrorKind> for Error {
41    fn from(kind: ErrorKind) -> Self {
42        Error(kind)
43    }
44}
45
46impl fmt::Display for Error {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        match &self.0 {
49            ErrorKind::Raw(error) => write!(f, "{}", error),
50            ErrorKind::Hyper(error) => write!(f, "{}", error),
51            ErrorKind::Http(error) => write!(f, "{}", error),
52            ErrorKind::Io(error) => write!(f, "{}", error),
53            ErrorKind::InvalidMultipartFilename => write!(f, "invalid multipart filename"),
54        }
55    }
56}
57
58impl error::Error for Error {}