wrapper to log failing urls

This commit is contained in:
Matthias 2021-11-20 13:37:16 +01:00
parent e925095503
commit 57aefc8100
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -4,6 +4,8 @@ URL lookup for plugin app
from django.conf import settings from django.conf import settings
from django.conf.urls import url, include from django.conf.urls import url, include
from plugin.helpers import get_plugin_error
PLUGIN_BASE = 'plugin' # Constant for links PLUGIN_BASE = 'plugin' # Constant for links
@ -14,4 +16,16 @@ def get_plugin_urls():
for plugin in settings.INTEGRATION_PLUGINS.values(): for plugin in settings.INTEGRATION_PLUGINS.values():
if plugin.mixin_enabled('urls'): if plugin.mixin_enabled('urls'):
urls.append(plugin.urlpatterns) urls.append(plugin.urlpatterns)
# TODO wrap everything in plugin_url_wrapper
return url(f'^{PLUGIN_BASE}/', include((urls, 'plugin'))) 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