diff --git a/examples/reverse-proxy/src/main.rs b/examples/reverse-proxy/src/main.rs index 875a3a5a..7ce7e83e 100644 --- a/examples/reverse-proxy/src/main.rs +++ b/examples/reverse-proxy/src/main.rs @@ -15,7 +15,7 @@ use axum::{ routing::get, Router, }; -use hyper::client::HttpConnector; +use hyper::{client::HttpConnector, StatusCode}; type Client = hyper::client::Client; @@ -34,7 +34,7 @@ async fn main() { axum::serve(listener, app).await.unwrap(); } -async fn handler(State(client): State, mut req: Request) -> Response { +async fn handler(State(client): State, mut req: Request) -> Result { let path = req.uri().path(); let path_query = req .uri() @@ -46,7 +46,11 @@ async fn handler(State(client): State, mut req: Request) -> Response { *req.uri_mut() = Uri::try_from(uri).unwrap(); - client.request(req).await.unwrap().into_response() + Ok(client + .request(req) + .await + .map_err(|_| StatusCode::BAD_REQUEST)? + .into_response()) } async fn server() {