Skip to main content

weirdnet_push/
error.rs

1/// Errors from this crate.
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4    /// A wake payload is the wrong size, malformed, or doesn't open with this key and handle.
5    #[error("bad wake payload")]
6    BadPayload,
7    /// A payload was seen before or is too old or too far in the future.
8    #[error("replayed or stale wake")]
9    Replay,
10    /// The handle is unknown or revoked.
11    #[error("unknown or revoked wake handle")]
12    Gone,
13    /// The control secret doesn't match.
14    #[error("wrong control secret")]
15    Unauthorized,
16    /// A request or config is invalid.
17    #[error("invalid: {0}")]
18    Invalid(String),
19    /// Delivery to APNs, FCM or a relay failed.
20    #[error("delivery: {0}")]
21    Delivery(String),
22    /// The server answered with an error.
23    #[error("server: {status}: {message}")]
24    Server {
25        /// HTTP status.
26        status: u16,
27        /// Its message.
28        message: String,
29    },
30    /// HTTP transport.
31    #[cfg(feature = "client")]
32    #[error(transparent)]
33    Http(#[from] reqwest::Error),
34    /// Key material.
35    #[error("keys: {0}")]
36    Keys(String),
37    /// I/O.
38    #[error(transparent)]
39    Io(#[from] std::io::Error),
40}
41
42impl From<weirdnet_keys::KeysError> for Error {
43    fn from(e: weirdnet_keys::KeysError) -> Self {
44        Error::Keys(e.to_string())
45    }
46}
47
48/// `Result` with [`Error`].
49pub type Result<T, E = Error> = std::result::Result<T, E>;