derive std::error::Error for ProxyError
This commit is contained in:
parent
102d50a024
commit
1ae654b137
@ -27,6 +27,7 @@ hyper = { version = "0.14.18", features = ["client"] }
|
||||
lazy_static = "1.4.0"
|
||||
tokio = { version = "1.17.0", features = ["io-util", "rt"] }
|
||||
tracing = "0.1.34"
|
||||
thiserror = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
hyper = { version = "0.14.18", features = ["server"] }
|
||||
|
23
src/lib.rs
23
src/lib.rs
@ -118,6 +118,7 @@ use hyper::upgrade::OnUpgrade;
|
||||
use hyper::{Body, Client, Error, Request, Response, StatusCode};
|
||||
use lazy_static::lazy_static;
|
||||
use std::net::IpAddr;
|
||||
use thiserror::Error as ThisError;
|
||||
use tokio::io::copy_bidirectional;
|
||||
|
||||
lazy_static! {
|
||||
@ -142,26 +143,18 @@ lazy_static! {
|
||||
static ref X_FORWARDED_FOR: HeaderName = HeaderName::from_static("x-forwarded-for");
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, ThisError)]
|
||||
pub enum ProxyError {
|
||||
InvalidUri(InvalidUri),
|
||||
HyperError(Error),
|
||||
#[error("{0}")]
|
||||
InvalidUri(#[from] InvalidUri),
|
||||
#[error("{0}")]
|
||||
HyperError(#[from] Error),
|
||||
#[error("ForwardHeaderError")]
|
||||
ForwardHeaderError,
|
||||
#[error("UpgradeError: {0}")]
|
||||
UpgradeError(String),
|
||||
}
|
||||
|
||||
impl From<Error> for ProxyError {
|
||||
fn from(err: Error) -> ProxyError {
|
||||
ProxyError::HyperError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InvalidUri> for ProxyError {
|
||||
fn from(err: InvalidUri) -> ProxyError {
|
||||
ProxyError::InvalidUri(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ToStrError> for ProxyError {
|
||||
fn from(_err: ToStrError) -> ProxyError {
|
||||
ProxyError::ForwardHeaderError
|
||||
|
Loading…
Reference in New Issue
Block a user