mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-05 08:57:19 +02:00
Catch exceptions raised when rendering embedded plugin content
This commit is contained in:
12
netbox/templates/ui/exception.html
Normal file
12
netbox/templates/ui/exception.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% load i18n %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<div class="alert-icon">
|
||||
<i class="mdi mdi-alert"></i>
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
{% blocktrans %}An error occurred when loading content from plugin {{ plugin }}:{% endblocktrans %}
|
||||
</p>
|
||||
<pre class="p-0">{{ exception }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,5 +1,6 @@
|
||||
from django import template as template_
|
||||
from django.conf import settings
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from netbox.plugins import PluginTemplateExtension
|
||||
@@ -38,8 +39,11 @@ def _get_registered_content(obj, method, template_context):
|
||||
context['config'] = settings.PLUGINS_CONFIG.get(plugin_name, {})
|
||||
|
||||
# Call the method to render content
|
||||
instance = template_extension(context)
|
||||
content = getattr(instance, method)()
|
||||
try:
|
||||
instance = template_extension(context)
|
||||
content = getattr(instance, method)()
|
||||
except Exception as e:
|
||||
content = render_to_string('ui/exception.html', {'plugin': plugin_name, 'exception': repr(e)})
|
||||
html += content
|
||||
|
||||
return mark_safe(html)
|
||||
|
||||
Reference in New Issue
Block a user