From 1b5359add715249e6d887aeb29f918281ba2748a Mon Sep 17 00:00:00 2001 From: Eduardo Canellas Date: Tue, 24 Aug 2021 02:42:13 -0300 Subject: [PATCH] small changes to error handling example (#250) --- .../src/main.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/error-handling-and-dependency-injection/src/main.rs b/examples/error-handling-and-dependency-injection/src/main.rs index 7ffa75d8..860a86e5 100644 --- a/examples/error-handling-and-dependency-injection/src/main.rs +++ b/examples/error-handling-and-dependency-injection/src/main.rs @@ -96,23 +96,20 @@ impl IntoResponse for AppError { type BodyError = Infallible; fn into_response(self) -> Response { - let (status, error_json) = match self { + let (status, error_message) = match self { AppError::UserRepo(UserRepoError::NotFound) => { - (StatusCode::NOT_FOUND, json!("User not found")) + (StatusCode::NOT_FOUND, "User not found") } AppError::UserRepo(UserRepoError::InvalidUsername) => { - (StatusCode::UNPROCESSABLE_ENTITY, json!("Invalid username")) + (StatusCode::UNPROCESSABLE_ENTITY, "Invalid username") } }; - let mut response = Json(json!({ - "error": error_json, - })) - .into_response(); + let body = Json(json!({ + "error": error_message, + })); - *response.status_mut() = status; - - response + (status, body).into_response() } }