use crate::{response::Response, signer::SignerError};
use std::io;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("Error serializing to JSON: {0}")]
SerializeError(#[from] serde_json::Error),
#[error("Error connecting to APNs: {0}")]
ConnectionError(#[from] hyper::Error),
#[error("Http client error: {0}")]
ClientError(#[from] hyper_util::client::legacy::Error),
#[error("Error creating a signature: {0}")]
SignerError(#[from] SignerError),
#[error(
"Notification was not accepted by APNs (reason: {})",
.0.error
.as_ref()
.map(|e| e.reason.to_string())
.unwrap_or_else(|| "Unknown".to_string())
)]
ResponseError(Response),
#[error("Invalid options for APNs payload: {0}")]
InvalidOptions(String),
#[error("Error in reading a certificate file: {0}")]
ReadError(#[from] io::Error),
#[error("Error building TLS config: {0}")]
Tls(#[from] rustls::Error),
#[error("Failed to construct HTTP request: {0}")]
BuildRequestError(#[source] http::Error),
#[error("The request timed out after {0} s")]
RequestTimeout(u64),
#[cfg(all(not(feature = "openssl"), feature = "ring"))]
#[error("Unexpected private key: {0}")]
UnexpectedKey(#[from] ring::error::KeyRejected),
#[error("Invalid certificate")]
InvalidCertificate,
}
#[cfg(feature = "openssl")]
impl From<openssl::error::ErrorStack> for Error {
fn from(e: openssl::error::ErrorStack) -> Self {
Self::SignerError(SignerError::OpenSSL(e))
}
}