1use crate::{response::Response, signer::SignerError};
3use std::io;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
7pub enum Error {
8 #[error("Error serializing to JSON: {0}")]
10 SerializeError(#[from] serde_json::Error),
11
12 #[error("Error connecting to APNs: {0}")]
14 ConnectionError(#[from] hyper::Error),
15
16 #[error("Http client error: {0}")]
17 ClientError(#[from] hyper_util::client::legacy::Error),
18
19 #[error("Error creating a signature: {0}")]
21 SignerError(#[from] SignerError),
22
23 #[error(
27 "Notification was not accepted by APNs (reason: {})",
28 .0.error
29 .as_ref()
30 .map(|e| e.reason.to_string())
31 .unwrap_or_else(|| "Unknown".to_string())
32 )]
33 ResponseError(Response),
34
35 #[error("Invalid options for APNs payload: {0}")]
38 InvalidOptions(String),
39
40 #[error("Error in reading a certificate file: {0}")]
42 ReadError(#[from] io::Error),
43
44 #[error("Error building TLS config: {0}")]
45 Tls(#[from] rustls::Error),
46
47 #[error("Failed to construct HTTP request: {0}")]
49 BuildRequestError(#[source] http::Error),
50
51 #[error("The request timed out after {0} s")]
53 RequestTimeout(u64),
54
55 #[cfg(feature = "aws-lc-rs")]
57 #[error("Unexpected private key: {0}")]
58 UnexpectedKey(#[from] aws_lc_rs::error::KeyRejected),
59
60 #[error("Invalid certificate")]
61 InvalidCertificate,
62}
63
64#[cfg(all(not(feature = "aws-lc-rs"), feature = "openssl"))]
65impl From<openssl::error::ErrorStack> for Error {
66 fn from(e: openssl::error::ErrorStack) -> Self {
67 Self::SignerError(SignerError::OpenSSL(e))
68 }
69}