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 58 59 60 61 62 63 64
use serde_derive::Deserialize; use std::fmt; #[derive(Deserialize)] #[serde(untagged)] pub enum Error { #[serde(skip_deserializing)] PubSubAuth(goauth::error::GOErr), #[serde(skip_deserializing)] Http(hyper::Error), #[serde(skip_deserializing)] Json(serde_json::Error), #[serde(skip_deserializing)] Base64(base64::DecodeError), PubSub { code: i32, message: String, status: String, }, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::PubSubAuth(e) => write!(f, "PubSubAuth({})", e), Error::Http(e) => write!(f, "Hyper({})", e), Error::Json(e) => write!(f, "Json({})", e), Error::Base64(e) => write!(f, "Base64({})", e), Error::PubSub { code, message, status, } => write!( f, "PubSub(code: {}, status: {}, message: {})", code, status, message ), } } } impl From<goauth::error::GOErr> for Error { fn from(err: goauth::error::GOErr) -> Error { Error::PubSubAuth(err) } } impl From<hyper::Error> for Error { fn from(err: hyper::Error) -> Error { Error::Http(err) } } impl From<serde_json::Error> for Error { fn from(err: serde_json::Error) -> Error { Error::Json(err) } } impl From<base64::DecodeError> for Error { fn from(err: base64::DecodeError) -> Error { Error::Base64(err) } }