mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 12:36:45 +00:00
refactor integration error logging into helper
This commit is contained in:
parent
ebe712312c
commit
9087cabe5f
@ -14,6 +14,7 @@ from wsgiref.util import FileWrapper
|
|||||||
from django.http import StreamingHttpResponse
|
from django.http import StreamingHttpResponse
|
||||||
from django.core.exceptions import ValidationError, FieldError
|
from django.core.exceptions import ValidationError, FieldError
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from django.contrib.auth.models import Permission
|
from django.contrib.auth.models import Permission
|
||||||
|
|
||||||
@ -696,3 +697,11 @@ def clean_decimal(number):
|
|||||||
return Decimal(0)
|
return Decimal(0)
|
||||||
|
|
||||||
return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize()
|
return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize()
|
||||||
|
|
||||||
|
def log_plugin_error(error, reference: str = 'general'):
|
||||||
|
# make sure the registry is set up
|
||||||
|
if reference not in settings.INTEGRATION_ERRORS:
|
||||||
|
settings.INTEGRATION_ERRORS[reference] = []
|
||||||
|
|
||||||
|
# add error to stack
|
||||||
|
settings.INTEGRATION_ERRORS[reference].append(error)
|
||||||
|
@ -9,6 +9,8 @@ import logging
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import AppRegistryNotReady
|
from django.core.exceptions import AppRegistryNotReady
|
||||||
|
|
||||||
|
from InvenTree.helpers import log_plugin_error
|
||||||
|
|
||||||
# Action plugins
|
# Action plugins
|
||||||
import plugin.builtin.action as action
|
import plugin.builtin.action as action
|
||||||
from plugin.action import ActionPlugin
|
from plugin.action import ActionPlugin
|
||||||
@ -43,14 +45,10 @@ def get_modules(pkg, recursive: bool = False):
|
|||||||
pass
|
pass
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
# this 'protects' against malformed plugin modules by more or less silently failing
|
# this 'protects' against malformed plugin modules by more or less silently failing
|
||||||
# TODO log
|
# TODO log to logging
|
||||||
|
|
||||||
# make sure the registry is set up
|
# log to stack
|
||||||
if 'discovery' not in settings.INTEGRATION_ERRORS:
|
log_plugin_error({name: str(error)}, 'discovery')
|
||||||
settings.INTEGRATION_ERRORS['discovery'] = []
|
|
||||||
|
|
||||||
# add error to stack
|
|
||||||
settings.INTEGRATION_ERRORS['discovery'].append({name: str(error)})
|
|
||||||
|
|
||||||
return [v for k, v in context.items()]
|
return [v for k, v in context.items()]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user