AC-612 Return appropriate status code for server errors. Catch IntegrityError via the API and return a 400 response with error message instead of server error.

This commit is contained in:
Chris Church
2013-11-06 23:44:48 -05:00
parent 475c0d87c2
commit 2b01cc7059
4 changed files with 21 additions and 5 deletions

View File

@@ -499,6 +499,12 @@ class ProjectsTest(BaseTest):
with self.current_user(self.super_django_user):
data = dict(name='xyz', user=self.super_django_user.pk)
self.post(url, data, expect=400)
# Test with null where we expect a string value.
with self.current_user(self.super_django_user):
data = dict(name='zyx', user=self.super_django_user.pk, kind='ssh',
sudo_username=None)
self.post(url, data, expect=400)
# FIXME: Check list as other users.

View File

@@ -2,18 +2,16 @@
# All Rights Reserved.
# Django
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.template import RequestContext
def handle_error(request, status=404):
context = {}
#print request.path, status
if request.path.startswith('/admin/'):
template_name = 'admin/%d.html' % status
else:
template_name = '%d.html' % status
return render_to_response(template_name, context,
context_instance=RequestContext(request))
return render(request, template_name, context, status=status)
def handle_403(request):
return handle_error(request, 403)