Feedback tweaks

This commit is contained in:
Brian Tiemann
2026-03-12 19:40:32 -04:00
parent 07238e9f9c
commit b95fdd3ea7
2 changed files with 7 additions and 8 deletions

View File

@@ -45,10 +45,10 @@ class ConfigTemplateRenderMixin:
try:
output = configtemplate.render(context=context)
except Exception as e:
return Response(
{'detail': configtemplate.format_render_error(e)},
status=HTTP_500_INTERNAL_SERVER_ERROR,
)
detail = configtemplate.format_render_error(e)
if request.accepted_renderer.format == 'txt':
return Response(detail, status=HTTP_500_INTERNAL_SERVER_ERROR)
return Response({'detail': detail}, status=HTTP_500_INTERNAL_SERVER_ERROR)
# If the client has requested "text/plain", return the raw content.
if request.accepted_renderer.format == 'txt':

View File

@@ -313,12 +313,11 @@ class ConfigTemplate(
def format_render_error(self, exc):
"""
Return a formatted error string for a rendering exception. When debug is enabled, the full
traceback is returned. Otherwise, a concise, user-facing message is returned.
Must be called from within the except block so that traceback.format_exc() is valid.
traceback for the provided exception is returned. Otherwise, a concise, user-facing message
is returned.
"""
if self.debug:
return traceback.format_exc()
return ''.join(traceback.format_exception(exc))
if isinstance(exc, TemplateError):
parts = [f"{type(exc).__name__}: {exc}"]
if getattr(exc, 'name', None):