Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
feat(errors): give more context on what model is involved when 404 No…
Browse files Browse the repository at this point in the history
…t Found is involved (#1096)

closes #893
  • Loading branch information
helgi committed Oct 3, 2016
1 parent 3ac0d53 commit d63fe7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rootfs/api/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.http import Http404
import logging
from rest_framework.compat import set_rollback
from rest_framework.exceptions import APIException, status
Expand Down Expand Up @@ -28,7 +29,12 @@ class ServiceUnavailable(APIException):


def custom_exception_handler(exc, context):
# Call REST framework's default exception handler first,
# give more context on the error since DRF masks it as Not Found
if isinstance(exc, Http404):
set_rollback()
return Response(str(exc), status=status.HTTP_404_NOT_FOUND)

# Call REST framework's default exception handler after specific 404 handling,
# to get the standard error response.
response = exception_handler(exc, context)

Expand Down
6 changes: 6 additions & 0 deletions rootfs/api/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,9 @@ def test_unauthorized_user_cannot_modify_config(self, mock_requests):
body = {'values': {'FOO': 'bar'}}
response = self.client.post(url, body)
self.assertEqual(response.status_code, 403)

def test_config_app_not_exists(self, mock_requests):
url = '/v2/apps/{}/config'.format('fake')
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.assertEqual(response.data, 'No App matches the given query.')

0 comments on commit d63fe7f

Please sign in to comment.