-
Notifications
You must be signed in to change notification settings - Fork 305
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
feat: Introduce a new standartized drf errors format #5223
Conversation
def format_error_response(self, error_response: ErrorResponse): | ||
old_error_response_data = drf_exception_handler(self.exc, self.context).data | ||
# For the compatibility reasons, we are keeping the old format of error response | ||
# and adding the new format of error response in the same response. | ||
# This is done to avoid breaking the existing clients. | ||
# New format uses the default error response format from drf_standardized_errors. | ||
new_error_response_data = super().format_error_response(error_response) | ||
data = {**old_error_response_data, "new_format_data": new_error_response_data} | ||
return data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is the main idea of the PR
@@ -2149,7 +2149,7 @@ def test_alert_group_resolve_resolution_note( | |||
response = client.post(url, format="json", **make_user_auth_headers(user, token)) | |||
# check that resolution note is required | |||
assert response.status_code == status.HTTP_400_BAD_REQUEST | |||
assert response.json()["code"] == AlertGroupAPIError.RESOLUTION_NOTE_REQUIRED.value | |||
assert response.json()["code"] == str(AlertGroupAPIError.RESOLUTION_NOTE_REQUIRED.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the error is raised as an exception, only string is possible
some of the exceptions that are raised outside of drf are not handled by drf-standartized-errors handler, especially in middleware. We need to address that before rolling this pr. Closing the PR for now |
What this PR does
This pull request aims to standardize error handling in the Django Rest Framework by implementing the drf_standardized_errors package. The changes involve:
Which issue(s) this PR closes
Related to [issue link here]
Checklist
pr:no public docs
PR label added if not required)release:
). These labels dictate how your PR willshow up in the autogenerated release notes.