Skip to content

Commit

Permalink
Merge pull request #335 from terencehonles/fix-django-rest-framework-…
Browse files Browse the repository at this point in the history
…exception-handler

fix exceptions in wrapped rest_framework exception handler
  • Loading branch information
waltjones committed Aug 17, 2020
2 parents ed6f0cd + dcee846 commit 3ad499c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions rollbar/contrib/django_rest_framework/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
try:
from django.core.exceptions import ImproperlyConfigured
except ImportError:
RestFrameworkExceptionHandler = None
else:
try:
from rest_framework.views import exception_handler as RestFrameworkExceptionHandler
except (ImportError, ImproperlyConfigured):
RestFrameworkExceptionHandler = None
ImproperlyConfigured = RuntimeError

del ImproperlyConfigured
try:
from rest_framework.views import exception_handler as _exception_handler
except (ImportError, ImproperlyConfigured):
_exception_handler = None


def post_exception_handler(exc, context):
Expand All @@ -18,5 +16,14 @@ def post_exception_handler(exc, context):
# because we cannot read the request data/stream more than once.
# This will allow us to see the parsed POST params in the rollbar
# exception log.
context['request']._request.POST = context['request'].data
return RestFrameworkExceptionHandler(exc, context)

if _exception_handler is None:
raise ImproperlyConfigured(
'Could not import rest_framework.views.exception_handler')

try:
context['request']._request.POST = context['request'].data
except Exception:
pass

return _exception_handler(exc, context)

0 comments on commit 3ad499c

Please sign in to comment.