1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #12167: Catch and report on exceptions raised when rendering a config template

This commit is contained in:
jeremystretch
2023-04-04 08:47:01 -04:00
parent 13cbb33c98
commit 1b5f926e17
2 changed files with 9 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
from jinja2.exceptions import TemplateError
from rest_framework.response import Response
from .nested_serializers import NestedConfigTemplateSerializer
@@ -32,7 +33,12 @@ class ConfigContextQuerySetMixin:
class ConfigTemplateRenderMixin:
def render_configtemplate(self, request, configtemplate, context):
output = configtemplate.render(context=context)
try:
output = configtemplate.render(context=context)
except TemplateError as e:
return Response({
'detail': f"An error occurred while rendering the template (line {e.lineno}): {e}"
}, status=500)
# If the client has requested "text/plain", return the raw content.
if request.accepted_renderer.format == 'txt':