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() } }