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