-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
A-axumC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.I-needs-decisionIssues in need of decision.Issues in need of decision.
Description
Feature Request
Motivation
People ask about short-circuiting from handler functions with non-IntoResponse
errors somewhat frequently.
We already have ErrorResponse
in axum::response
for returning different error types from a handler function conveniently. However, right now it is quite annoying to construct one from a non-IntoResponse
error type (see alternatives).
Proposal
Add
impl ErrorResponse {
fn internal_server_error(message: impl Display) -> Self {
(StatusCode::INTERNAL_SERVER_ERROR, message.to_string()).into()
}
}
to allow users to write
try_thing().map_err(ErrorResponse::internal_server_error)?;
Alternatives
-
Expose a free function, same thing but less verbose
try_thing().map_err(internal_server_error)?;
-
Do nothing. One can already do
try_thing().map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
Open questions
Should the internal_server_error
function log the error as well?
Metadata
Metadata
Assignees
Labels
A-axumC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.I-needs-decisionIssues in need of decision.Issues in need of decision.