mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +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
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
import sys
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.views.debug import ExceptionReporter
|
||||||
|
|
||||||
from error_report.models import Error
|
from error_report.models import Error
|
||||||
|
|
||||||
@ -54,15 +56,15 @@ def exception_handler(exc, context):
|
|||||||
|
|
||||||
response = Response(response_data, status=500)
|
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
|
# Log the exception to the database, too
|
||||||
|
kind, info, data = sys.exc_info()
|
||||||
|
|
||||||
Error.objects.create(
|
Error.objects.create(
|
||||||
kind="Unhandled API Exception",
|
kind=kind.__name__,
|
||||||
info=str(type(exc)),
|
info=info,
|
||||||
data=trace,
|
data='\n'.join(traceback.format_exception(kind, info, data)),
|
||||||
path=context['request'].path,
|
path=context['request'].path,
|
||||||
|
html=ExceptionReporter(context['request'], kind, info, data).get_traceback_html(),
|
||||||
)
|
)
|
||||||
|
|
||||||
if response is not None:
|
if response is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user