gcp_pubsub/
error.rs

1use serde_derive::Deserialize;
2use std::fmt;
3
4#[derive(Deserialize, Debug)]
5#[serde(untagged)]
6pub enum Error {
7  #[serde(skip_deserializing)]
8  PubSubAuth(goauth::error::GOErr),
9  #[serde(skip_deserializing)]
10  Json(serde_json::Error),
11  #[serde(skip_deserializing)]
12  Base64(base64::DecodeError),
13  #[serde(skip_deserializing)]
14  Unexpected(String),
15  #[serde(skip_deserializing)]
16  PubSub(String),
17  #[serde(skip_deserializing)]
18  IOError(std::io::Error),
19}
20
21impl fmt::Display for Error {
22  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23    match self {
24      Error::PubSubAuth(e) => write!(f, "PubSubAuth({})", e),
25      Error::Json(e) => write!(f, "Json({})", e),
26      Error::Base64(e) => write!(f, "Base64({})", e),
27      Error::Unexpected(message) => write!(f, "Unexpected({})", message),
28      Error::PubSub(message) => write!(f, "PubSub({})", message),
29      Error::IOError(e) => write!(f, "(IOErr{})", e),
30    }
31  }
32}
33
34impl From<goauth::error::GOErr> for Error {
35  fn from(err: goauth::error::GOErr) -> Error {
36    Error::PubSubAuth(err)
37  }
38}
39
40impl From<serde_json::Error> for Error {
41  fn from(err: serde_json::Error) -> Error {
42    Error::Json(err)
43  }
44}
45
46// impl From<base64::DecodeError> for Error {
47//   fn from(err: base64::DecodeError) -> Error {
48//     Error::Base64(err)
49//   }
50// }