modified exception handler to throw django error page in case of internal server error

This commit is contained in:
AKhil Lawrence 2016-06-05 14:40:57 +05:30
parent 1633a0a2b1
commit 6ceb8cfe93

View File

@ -3,15 +3,19 @@ Provides an APIView class that is the base of all views in REST framework.
"""
from __future__ import unicode_literals
import sys
from django.core.exceptions import PermissionDenied
from django.db import models
from django.http import Http404
from django.http.response import HttpResponseBase
from django.http.response import HttpResponseBase, HttpResponse
from django.utils import six
from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View
from django.views import debug
from django.conf import settings
from rest_framework import exceptions, status
from rest_framework.compat import set_rollback
@ -91,7 +95,11 @@ def exception_handler(exc, context):
set_rollback()
return Response(data, status=status.HTTP_403_FORBIDDEN)
# Note: Unhandled exceptions will raise a 500 error.
# throw django's error page if debug is True
if settings.DEBUG:
exception_reporter = debug.ExceptionReporter(context.get('request'), *sys.exc_info())
return HttpResponse(exception_reporter.get_traceback_html(), status=500)
return None