mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-13 05:45:48 +01:00
Feedback tweaks
This commit is contained in:
@@ -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':
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user