diff --git a/dajaxice/tests/__init__.py b/dajaxice/tests/__init__.py index fb918e5..f4bd058 100644 --- a/dajaxice/tests/__init__.py +++ b/dajaxice/tests/__init__.py @@ -137,7 +137,7 @@ def test_calling_registered_function_with_params(self): def test_bad_function(self): response = self.client.post('/dajaxice/dajaxice.tests.test_ajax_exception/') - self.failUnlessEqual(response.status_code, 200) + self.failUnlessEqual(response.status_code, 500) self.failUnlessEqual(response.content, "DAJAXICE_EXCEPTION") def test_get_register(self): diff --git a/dajaxice/views.py b/dajaxice/views.py index 63911ec..d9afb55 100644 --- a/dajaxice/views.py +++ b/dajaxice/views.py @@ -48,13 +48,18 @@ def dispatch(self, request, name=None): data = {} # Call the function. If something goes wrong, handle the Exception + status = 200 try: response = function.call(request, **data) except Exception: if settings.DEBUG: raise response = dajaxice_config.DAJAXICE_EXCEPTION + status = 500 - return HttpResponse(response, mimetype="application/x-json") + if isinstance(response, basestring): + return HttpResponse(response, status=status, mimetype="application/json") + else: + return response else: raise FunctionNotCallableError(name)