Have rest_dispatch return JSON when exceptions are thrown.

(imported from commit 587a8f46d406c6358480db9e0ebd5afb69e12abf)
This commit is contained in:
Steve Howell
2013-12-13 15:52:20 -05:00
parent f929e51776
commit 44b738ab75
2 changed files with 13 additions and 2 deletions

View File

@@ -4,10 +4,12 @@ from django.views.decorators.csrf import csrf_exempt, csrf_protect
from zerver.decorator import authenticated_json_view, authenticated_rest_api_view, \
process_as_post
from zerver.lib.response import json_method_not_allowed, json_unauthorized
from zerver.lib.response import json_method_not_allowed, json_unauthorized, json_unhandled_exception
from django.http import HttpResponseRedirect
from django.conf import settings
import logging
METHODS = ('GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH')
@@ -77,7 +79,13 @@ def rest_dispatch(request, globals_list, **kwargs):
# otherwise we might access and thus cache a value for
# request.REQUEST.
target_function = process_as_post(target_function)
return target_function(request, **kwargs)
try:
return target_function(request, **kwargs)
except:
logging.exception('Uncaught exception in rest_dispatch')
return json_unhandled_exception()
return json_method_not_allowed(supported_methods.keys())