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