hyper_client_pool/
error.rs

1use std::io;
2
3use crate::deliverable::Deliverable;
4use crate::transaction::Transaction;
5
6/// Error when spawning and configuring the thread that the [`hyper::Client`]s run on.
7#[derive(Debug)]
8pub enum SpawnError {
9    ThreadSpawn(io::Error),
10    HttpsConnector(native_tls::Error),
11}
12
13impl PartialEq for SpawnError {
14    fn eq(&self, other: &SpawnError) -> bool {
15        match self {
16            SpawnError::ThreadSpawn(_err) => match other {
17                SpawnError::ThreadSpawn(_oerr) => true,
18                _ => false,
19            },
20            SpawnError::HttpsConnector(_err) => match other {
21                SpawnError::HttpsConnector(_oerr) => true,
22                _ => false,
23            },
24        }
25    }
26}
27
28impl From<native_tls::Error> for SpawnError {
29    fn from(err: native_tls::Error) -> SpawnError {
30        SpawnError::HttpsConnector(err)
31    }
32}
33
34/// An error returned when requesting a Transaction.
35#[derive(Debug)]
36pub struct Error<D: Deliverable> {
37    pub kind: ErrorKind,
38    transaction: Transaction<D>,
39}
40
41impl<D: Deliverable> Error<D> {
42    pub(crate) fn new(kind: ErrorKind, transaction: Transaction<D>) -> Error<D> {
43        Error { kind, transaction }
44    }
45
46    pub fn into_inner(self) -> Transaction<D> {
47        self.transaction
48    }
49}
50
51/// Types of errors that can occur when requesting.
52/// A [`SpawnError`] can occur when requesting a Transaction as a new thread may need
53/// spawned if a previous one was lost / invalidated.
54#[derive(Debug, PartialEq)]
55pub enum ErrorKind {
56    /// An error occurred when spawning and configuring a new thread for a hyper::Client
57    Spawn(SpawnError),
58    /// There is no room for another transaction right now, the pool is full.
59    PoolFull,
60}
61
62/// Type of errors that can occur when attempting to send a [`Transaction`]
63/// to an [`Executor`].
64pub(crate) enum RequestError<D: Deliverable> {
65    PoolFull(Transaction<D>),
66    FailedSend(Transaction<D>),
67}