Skip to content
Snippets Groups Projects
Commit 93a91897 authored by Martin Burchell's avatar Martin Burchell
Browse files

Improved error message for non-existent taxonomy

parent 06af145a
No related branches found
No related tags found
No related merge requests found
......@@ -126,4 +126,4 @@ def test_error_for_non_existent_taxonomy():
response = get_term_itemcount_response('a-taxonomy-that-does-not-exist')
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data['detail'] == "Taxonomy matching query does not exist."
assert response.data['detail'] == "Taxonomy with slug 'a-taxonomy-that-does-not-exist' does not exist."
from django.db.models import Count
from django.utils.translation import ugettext as _
from rest_framework import viewsets, status
from rest_framework_bulk.mixins import BulkDestroyModelMixin
......@@ -63,8 +64,10 @@ class TaxonomyViewSet(viewsets.ModelViewSet):
def itemcount(self, request, slug):
try:
taxonomy = Taxonomy.objects.get(slug=slug)
except Taxonomy.DoesNotExist as e:
data = {'detail': e.message}
except Taxonomy.DoesNotExist:
message = _("Taxonomy with slug '%s' does not exist.") % (slug)
data = {'detail': message}
return Response(data, status=status.HTTP_400_BAD_REQUEST)
terms = Term.objects.filter(taxonomy=taxonomy).annotate(count=Count('message'))
......
......@@ -53,4 +53,4 @@ def test_itemcount_fails_if_taxonomy_does_not_exist(item_data):
error = excinfo.value.message
assert error['status_code'] == 400
assert error['detail'] == "Taxonomy matching query does not exist."
assert error['detail'] == "Taxonomy with slug 'a-taxonomy-that-does-not-exist' does not exist."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment