mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Copy error implementation from django-error-report lib
Ref: https://github.com/mhsiddiqui/django-error-report/blob/master/error_report/middleware.py
This commit is contained in:
parent
048f1ad601
commit
027a7c88de
@ -6,10 +6,12 @@ Custom exception handling for the DRF API
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.debug import ExceptionReporter
|
||||
|
||||
from error_report.models import Error
|
||||
|
||||
@ -54,15 +56,15 @@ def exception_handler(exc, context):
|
||||
|
||||
response = Response(response_data, status=500)
|
||||
|
||||
# Format error traceback
|
||||
trace = ''.join(traceback.format_exception(type(exc), exc, exc.__traceback__))
|
||||
|
||||
# Log the exception to the database, too
|
||||
kind, info, data = sys.exc_info()
|
||||
|
||||
Error.objects.create(
|
||||
kind="Unhandled API Exception",
|
||||
info=str(type(exc)),
|
||||
data=trace,
|
||||
kind=kind.__name__,
|
||||
info=info,
|
||||
data='\n'.join(traceback.format_exception(kind, info, data)),
|
||||
path=context['request'].path,
|
||||
html=ExceptionReporter(context['request'], kind, info, data).get_traceback_html(),
|
||||
)
|
||||
|
||||
if response is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user