Skip to content

Commit

Permalink
Merge branch 'master' into extend-app-context-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad authored Jan 8, 2025
2 parents 3ef5baa + b4abb30 commit 2764721
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
(
Expand All @@ -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"),
),
};

Expand Down
7 changes: 4 additions & 3 deletions tests/controller/into_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2764721

Please sign in to comment.