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

fix exceptions in wrapped rest_framework exception handler #335

Merged
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
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)