From 6aec40b9ba647ea1352113132e97d82d4f42073c Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 17 Feb 2022 23:46:43 +1100 Subject: [PATCH] Improved error messages when report templates (or snippets) are missing! --- InvenTree/report/api.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/InvenTree/report/api.py b/InvenTree/report/api.py index af88f4799f..710f0562b1 100644 --- a/InvenTree/report/api.py +++ b/InvenTree/report/api.py @@ -225,13 +225,15 @@ class ReportPrintMixin: outputs.append(report.render_as_string(request)) else: outputs.append(report.render(request)) - except TemplateDoesNotExist: - - filename = report.template - + except TemplateDoesNotExist as e: + + template = str(e) + if not template: + template = report.template + return Response( { - 'error': _(f"Template file '{filename}' is missing or does not exist"), + 'error': _(f"Template file '{template}' is missing or does not exist"), }, status=400, ) @@ -269,13 +271,16 @@ class ReportPrintMixin: else: pdf = outputs[0].get_document().write_pdf() - except TemplateDoesNotExist: + except TemplateDoesNotExist as e: - filename = report.template + template = str(e) + + if not template: + template = report.template return Response( { - 'error': _(f"Template file '{filename}' is missing or does not exist"), + 'error': _(f"Template file '{template}' is missing or does not exist"), }, status=400, )