mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Improve error logging (#5039)
- Truncate path to < 200 chars - Prevents exception when creating new Error object
This commit is contained in:
parent
00bb740216
commit
a3940cfc41
@ -167,4 +167,31 @@ class InvenTreeExceptionProcessor(ExceptionProcessor):
|
|||||||
if kind in settings.IGNORED_ERRORS:
|
if kind in settings.IGNORED_ERRORS:
|
||||||
return
|
return
|
||||||
|
|
||||||
return super().process_exception(request, exception)
|
import traceback
|
||||||
|
|
||||||
|
from django.views.debug import ExceptionReporter
|
||||||
|
|
||||||
|
from error_report.models import Error
|
||||||
|
from error_report.settings import ERROR_DETAIL_SETTINGS
|
||||||
|
|
||||||
|
# Error reporting is disabled
|
||||||
|
if not ERROR_DETAIL_SETTINGS.get('ERROR_DETAIL_ENABLE', True):
|
||||||
|
return
|
||||||
|
|
||||||
|
path = request.build_absolute_uri()
|
||||||
|
|
||||||
|
# Truncate the path to a reasonable length
|
||||||
|
# Otherwise we get a database error,
|
||||||
|
# because the path field is limited to 200 characters
|
||||||
|
if len(path) > 200:
|
||||||
|
path = path[:195] + '...'
|
||||||
|
|
||||||
|
error = Error.objects.create(
|
||||||
|
kind=kind.__name__,
|
||||||
|
html=ExceptionReporter(request, kind, info, data).get_traceback_html(),
|
||||||
|
path=path,
|
||||||
|
info=info,
|
||||||
|
data='\n'.join(traceback.format_exception(kind, info, data)),
|
||||||
|
)
|
||||||
|
|
||||||
|
error.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user