1use serde_derive::Deserialize;
2use std::fmt;
3use std::io;
4
5#[derive(Deserialize, Debug)]
6#[serde(untagged)]
7pub enum Error {
8 #[serde(skip_deserializing)]
9 PubSubAuth(goauth::GoErr),
10 #[serde(skip_deserializing)]
11 Http(hyper::Error),
12 #[serde(skip_deserializing)]
13 Json(serde_json::Error),
14 #[serde(skip_deserializing)]
15 Base64(base64::DecodeError),
16 #[serde(skip_deserializing)]
17 IO(io::Error),
18 PubSub {
19 code: i32,
20 message: String,
21 status: String,
22 },
23}
24
25impl fmt::Display for Error {
26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27 match self {
28 Error::PubSubAuth(e) => write!(f, "PubSubAuth({})", e),
29 Error::Http(e) => write!(f, "Hyper({})", e),
30 Error::Json(e) => write!(f, "Json({})", e),
31 Error::Base64(e) => write!(f, "Base64({})", e),
32 Error::IO(e) => write!(f, "IO({})", e),
33 Error::PubSub {
34 code,
35 message,
36 status,
37 } => write!(
38 f,
39 "PubSub(code: {}, status: {}, message: {})",
40 code, status, message
41 ),
42 }
43 }
44}
45
46impl std::error::Error for Error {}
47
48impl From<goauth::GoErr> for Error {
49 fn from(err: goauth::GoErr) -> Error {
50 Error::PubSubAuth(err)
51 }
52}
53
54impl From<hyper::Error> for Error {
55 fn from(err: hyper::Error) -> Error {
56 Error::Http(err)
57 }
58}
59
60impl From<serde_json::Error> for Error {
61 fn from(err: serde_json::Error) -> Error {
62 Error::Json(err)
63 }
64}
65
66impl From<base64::DecodeError> for Error {
67 fn from(err: base64::DecodeError) -> Error {
68 Error::Base64(err)
69 }
70}
71
72impl From<io::Error> for Error {
73 fn from(err: io::Error) -> Error {
74 Error::IO(err)
75 }
76}