axum_proxy/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3
4#[cfg(feature = "axum")]
5use axum::response::{IntoResponse, Response};
6use http::Error as HttpError;
7use hyper_util::client::legacy::Error as HyperError;
8
9#[derive(Debug)]
10pub enum ProxyError {
11    InvalidUri(HttpError),
12    RequestFailed(HyperError),
13}
14
15impl fmt::Display for ProxyError {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match *self {
18            Self::InvalidUri(ref e) => {
19                write!(f, "Invalid uri: {}", e)
20            },
21            Self::RequestFailed(ref e) => {
22                write!(f, "Request failed: {}", e)
23            },
24        }
25    }
26}
27
28impl StdError for ProxyError {}
29
30#[cfg(feature = "axum")]
31#[cfg_attr(docsrs, doc(cfg(feature = "axum")))]
32impl IntoResponse for ProxyError {
33    fn into_response(self) -> Response {
34        use http::StatusCode;
35        use tracing::{Level, event};
36
37        event!(Level::ERROR, error = %self);
38
39        StatusCode::INTERNAL_SERVER_ERROR.into_response()
40    }
41}