Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make internal server error new fallback error type #1092

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading