Fixes #7109: When handling an exception during an API query, send an error response containing structured information about the error rather than HTML

This commit is contained in:
thatmattlove 2021-09-01 00:21:47 -07:00
parent 691c66d2f5
commit 93b9b6d01c
2 changed files with 4 additions and 1 deletions

View File

@ -23,6 +23,7 @@
* [#7101](https://github.com/netbox-community/netbox/issues/7101) - Enforce `MAX_PAGE_SIZE` for table and REST API pagination * [#7101](https://github.com/netbox-community/netbox/issues/7101) - Enforce `MAX_PAGE_SIZE` for table and REST API pagination
* [#7106](https://github.com/netbox-community/netbox/issues/7106) - Fix incorrect "Map It" button URL on a site's Physical Address field * [#7106](https://github.com/netbox-community/netbox/issues/7106) - Fix incorrect "Map It" button URL on a site's Physical Address field
* [#7107](https://github.com/netbox-community/netbox/issues/7107) - Fix missing search button and search results in IP Address assignment "Assign IP" tab * [#7107](https://github.com/netbox-community/netbox/issues/7107) - Fix missing search button and search results in IP Address assignment "Assign IP" tab
* [#7109](https://github.com/netbox-community/netbox/issues/7109) - When handling an exception during an API query, send an error response containing structured information about the error rather than HTML.
--- ---

View File

@ -22,7 +22,7 @@ from extras.models import ExportTemplate
from netbox.api import BulkOperationSerializer from netbox.api import BulkOperationSerializer
from netbox.api.authentication import IsAuthenticatedOrLoginNotRequired from netbox.api.authentication import IsAuthenticatedOrLoginNotRequired
from netbox.api.exceptions import SerializerNotFound from netbox.api.exceptions import SerializerNotFound
from utilities.api import get_serializer_for_model from utilities.api import get_serializer_for_model, rest_api_server_error
HTTP_ACTIONS = { HTTP_ACTIONS = {
'GET': 'view', 'GET': 'view',
@ -210,6 +210,8 @@ class ModelViewSet(BulkUpdateModelMixin, BulkDestroyModelMixin, ModelViewSet_):
*args, *args,
**kwargs **kwargs
) )
except Exception as e:
return rest_api_server_error(request, *args, **kwargs)
def _validate_objects(self, instance): def _validate_objects(self, instance):
""" """