From 99e8828df5ef7fa3f5412d781a60179aa000ad5b Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Sat, 1 Jul 2023 23:08:49 +0200 Subject: [PATCH] Remove unwrap from example-reverse-proxy --- examples/reverse-proxy/src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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() {