Skip to content

Added generic 500 and 400 JSON error handlers. #5904

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

Merged
merged 4 commits into from
Apr 3, 2018

Conversation

carltongibson
Copy link
Collaborator

Closes #4556

Adds generic handlers for generic server error and bad request errors. (To be used with Django's handler500 and handler400.)

Unit tests on functions themselves but no integration tests, since the test client insists on re-raising any exceptions, rather than processing the error view.

@carltongibson carltongibson added this to the 3.8 Release milestone Mar 27, 2018

# Generic Error Views

Django REST Framework provides two error views suitable for providing generic JSON `500` Server Error and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! We might want to just outline the motivation here, ie “Django’s defaults give you HTML responses”

@carltongibson carltongibson merged commit 1befab7 into encode:master Apr 3, 2018
@carltongibson carltongibson deleted the 38/error-handlers branch April 3, 2018 07:16
Generic 500 error handler.
"""
data = {
'error': 'Server Error (500)'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using detail as the key here have been more consistent with other DRF errors? I excitedly ripped out my own custom error handlers for DRF's shiny new ones only to see that the key for error details was now something unexpected.

pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
* Added generic 500 and 400 JSON error handlers.
* Docs for generic error views.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants