From 57aefc81002aef9adc119498c0e1165edf25398f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 20 Nov 2021 13:37:16 +0100 Subject: [PATCH] wrapper to log failing urls --- InvenTree/plugin/urls.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/InvenTree/plugin/urls.py b/InvenTree/plugin/urls.py index 29c6ecb32e..8daa5041e2 100644 --- a/InvenTree/plugin/urls.py +++ b/InvenTree/plugin/urls.py @@ -4,6 +4,8 @@ URL lookup for plugin app from django.conf import settings from django.conf.urls import url, include +from plugin.helpers import get_plugin_error + PLUGIN_BASE = 'plugin' # Constant for links @@ -14,4 +16,16 @@ def get_plugin_urls(): for plugin in settings.INTEGRATION_PLUGINS.values(): if plugin.mixin_enabled('urls'): urls.append(plugin.urlpatterns) + # TODO wrap everything in plugin_url_wrapper return url(f'^{PLUGIN_BASE}/', include((urls, 'plugin'))) + + +def plugin_url_wrapper(view): + """wrapper to catch errors and log them to plugin error stack""" + def f(request, *args, **kwargs): + try: + return view(request, *args, **kwargs) + except Exception as error: + get_plugin_error(error, do_log=True, log_name='view') + # TODO disable if in production + return f