diff --git a/src/controller/mod.rs b/src/controller/mod.rs index 34f70a08..a6c231b2 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -198,10 +198,6 @@ impl IntoResponse for Error { StatusCode::NOT_FOUND, ErrorDetail::new("not_found", "Resource was not found"), ), - Self::InternalServerError => ( - StatusCode::INTERNAL_SERVER_ERROR, - ErrorDetail::new("internal_server_error", "Internal Server Error"), - ), Self::Unauthorized(err) => { tracing::warn!(err); ( @@ -221,9 +217,13 @@ impl IntoResponse for Error { ErrorDetail::with_reason("Bad Request"), ) } - _ => ( + Self::BadRequest(err) => ( StatusCode::BAD_REQUEST, - ErrorDetail::with_reason("Bad Request"), + ErrorDetail::new("Bad Request", &err), + ), + _ => ( + StatusCode::INTERNAL_SERVER_ERROR, + ErrorDetail::new("internal_server_error", "Internal Server Error"), ), }; diff --git a/tests/controller/into_response.rs b/tests/controller/into_response.rs index 4fe4379e..c68b90bd 100644 --- a/tests/controller/into_response.rs +++ b/tests/controller/into_response.rs @@ -56,7 +56,7 @@ async fn internal_server_error() { let expected_json = serde_json::json!({ "error": "internal_server_error", - "description": "Internal Server Error" + "description": "Internal Server Error", }); assert_eq!(res_json, expected_json); @@ -111,13 +111,14 @@ async fn fallback() { .await .expect("Valid response"); - assert_eq!(res.status(), 400); + assert_eq!(res.status(), 500); let res_text = res.text().await.expect("response text"); let res_json: serde_json::Value = serde_json::from_str(&res_text).expect("Valid JSON response"); let expected_json = serde_json::json!({ - "error": "Bad Request", + "error": "internal_server_error", + "description": "Internal Server Error", }); assert_eq!(res_json, expected_json);