1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Move rest_api_server_error() to utilities.api

This commit is contained in:
Jeremy Stretch
2020-11-10 17:19:14 -05:00
parent 4971469590
commit 2b359ce1c7
3 changed files with 24 additions and 21 deletions

View File

@@ -1,4 +1,10 @@
import platform
import sys
from django.conf import settings
from django.http import JsonResponse
from django.urls import reverse
from rest_framework import status
from rest_framework.utils import formatting
from netbox.api.exceptions import SerializerNotFound
@@ -50,3 +56,17 @@ def get_view_name(view, suffix=None):
name += ' ' + suffix
return name
def rest_api_server_error(request, *args, **kwargs):
"""
Handle exceptions and return a useful error message for REST API requests.
"""
type_, error, traceback = sys.exc_info()
data = {
'error': str(error),
'exception': type_.__name__,
'netbox_version': settings.VERSION,
'python_version': platform.python_version(),
}
return JsonResponse(data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)