use thiserror::Error;
use super::conn::connection::ConnectionError;
use super::{pool, BoxError};
#[derive(Debug, Error)]
pub enum Error {
#[error("connection: {0}")]
Connection(#[source] BoxError),
#[error("transport: {0}")]
Transport(#[source] BoxError),
#[error("protocol: {0}")]
Protocol(#[source] BoxError),
#[error("serivce: {0}")]
Service(#[source] BoxError),
#[error("user error: {0}")]
User(#[source] hyper::Error),
#[error("invalid method: {0}")]
InvalidMethod(http::Method),
#[error("unsupported protocol")]
UnsupportedProtocol,
#[error("request timeout")]
RequestTimeout,
}
impl From<pool::Error<ConnectionError>> for Error {
fn from(error: pool::Error<ConnectionError>) -> Self {
match error {
pool::Error::Connecting(error) => Error::Connection(error.into()),
pool::Error::Handshaking(error) => Error::Transport(error.into()),
pool::Error::Unavailable => {
Error::Connection("pool closed, no connection can be made".into())
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use static_assertions::assert_impl_all;
assert_impl_all!(Error: std::error::Error, Send, Sync, Into<Box<dyn std::error::Error + Send + Sync>>);
}