mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #7109: Ensure human readability of exceptions raised during REST API requests
This commit is contained in:
@ -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) - Ensure human readability of exceptions raised during REST API requests
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -113,6 +113,10 @@ class ExceptionHandlingMiddleware(object):
|
|||||||
|
|
||||||
def process_exception(self, request, exception):
|
def process_exception(self, request, exception):
|
||||||
|
|
||||||
|
# Handle exceptions that occur from REST API requests
|
||||||
|
if is_api_request(request):
|
||||||
|
return rest_api_server_error(request)
|
||||||
|
|
||||||
# Don't catch exceptions when in debug mode
|
# Don't catch exceptions when in debug mode
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
return
|
return
|
||||||
@ -121,10 +125,6 @@ class ExceptionHandlingMiddleware(object):
|
|||||||
if isinstance(exception, Http404):
|
if isinstance(exception, Http404):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Handle exceptions that occur from REST API requests
|
|
||||||
if is_api_request(request):
|
|
||||||
return rest_api_server_error(request)
|
|
||||||
|
|
||||||
# Determine the type of exception. If it's a common issue, return a custom error page with instructions.
|
# Determine the type of exception. If it's a common issue, return a custom error page with instructions.
|
||||||
custom_template = None
|
custom_template = None
|
||||||
if isinstance(exception, ProgrammingError):
|
if isinstance(exception, ProgrammingError):
|
||||||
|
@ -48,7 +48,8 @@ def is_api_request(request):
|
|||||||
Return True of the request is being made via the REST API.
|
Return True of the request is being made via the REST API.
|
||||||
"""
|
"""
|
||||||
api_path = reverse('api-root')
|
api_path = reverse('api-root')
|
||||||
return request.path_info.startswith(api_path)
|
|
||||||
|
return request.path_info.startswith(api_path) and request.content_type == 'application/json'
|
||||||
|
|
||||||
|
|
||||||
def get_view_name(view, suffix=None):
|
def get_view_name(view, suffix=None):
|
||||||
|
Reference in New Issue
Block a user