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

Commit d63fe7f

Browse files
authored
feat(errors): give more context on what model is involved when 404 Not Found is involved (#1096)
closes #893
1 parent 3ac0d53 commit d63fe7f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

rootfs/api/exceptions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.http import Http404
12
import logging
23
from rest_framework.compat import set_rollback
34
from rest_framework.exceptions import APIException, status
@@ -28,7 +29,12 @@ class ServiceUnavailable(APIException):
2829

2930

3031
def custom_exception_handler(exc, context):
31-
# Call REST framework's default exception handler first,
32+
# give more context on the error since DRF masks it as Not Found
33+
if isinstance(exc, Http404):
34+
set_rollback()
35+
return Response(str(exc), status=status.HTTP_404_NOT_FOUND)
36+
37+
# Call REST framework's default exception handler after specific 404 handling,
3238
# to get the standard error response.
3339
response = exception_handler(exc, context)
3440

rootfs/api/tests/test_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,9 @@ def test_unauthorized_user_cannot_modify_config(self, mock_requests):
325325
body = {'values': {'FOO': 'bar'}}
326326
response = self.client.post(url, body)
327327
self.assertEqual(response.status_code, 403)
328+
329+
def test_config_app_not_exists(self, mock_requests):
330+
url = '/v2/apps/{}/config'.format('fake')
331+
response = self.client.get(url)
332+
self.assertEqual(response.status_code, 404)
333+
self.assertEqual(response.data, 'No App matches the given query.')

0 commit comments

Comments
 (0)