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"
|
lazy_static = "1.4.0"
|
||||||
tokio = { version = "1.17.0", features = ["io-util", "rt"] }
|
tokio = { version = "1.17.0", features = ["io-util", "rt"] }
|
||||||
tracing = "0.1.34"
|
tracing = "0.1.34"
|
||||||
|
thiserror = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hyper = { version = "0.14.18", features = ["server"] }
|
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 hyper::{Body, Client, Error, Request, Response, StatusCode};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
use thiserror::Error as ThisError;
|
||||||
use tokio::io::copy_bidirectional;
|
use tokio::io::copy_bidirectional;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@ -142,26 +143,18 @@ lazy_static! {
|
|||||||
static ref X_FORWARDED_FOR: HeaderName = HeaderName::from_static("x-forwarded-for");
|
static ref X_FORWARDED_FOR: HeaderName = HeaderName::from_static("x-forwarded-for");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, ThisError)]
|
||||||
pub enum ProxyError {
|
pub enum ProxyError {
|
||||||
InvalidUri(InvalidUri),
|
#[error("{0}")]
|
||||||
HyperError(Error),
|
InvalidUri(#[from] InvalidUri),
|
||||||
|
#[error("{0}")]
|
||||||
|
HyperError(#[from] Error),
|
||||||
|
#[error("ForwardHeaderError")]
|
||||||
ForwardHeaderError,
|
ForwardHeaderError,
|
||||||
|
#[error("UpgradeError: {0}")]
|
||||||
UpgradeError(String),
|
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 {
|
impl From<ToStrError> for ProxyError {
|
||||||
fn from(_err: ToStrError) -> ProxyError {
|
fn from(_err: ToStrError) -> ProxyError {
|
||||||
ProxyError::ForwardHeaderError
|
ProxyError::ForwardHeaderError
|
||||||
|
Loading…
Reference in New Issue
Block a user