From 027a7c88de4644b3e6826e3be75605e6f9924f2e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 17 May 2022 01:17:48 +1000 Subject: [PATCH] Copy error implementation from django-error-report lib Ref: https://github.com/mhsiddiqui/django-error-report/blob/master/error_report/middleware.py --- InvenTree/InvenTree/exceptions.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/InvenTree/InvenTree/exceptions.py b/InvenTree/InvenTree/exceptions.py index 20d74fd4ac..8403cbf4c8 100644 --- a/InvenTree/InvenTree/exceptions.py +++ b/InvenTree/InvenTree/exceptions.py @@ -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: