From ec5ff6408dd21e49f902eb5be53e73970223d1b7 Mon Sep 17 00:00:00 2001 From: Lukas <76838159+wolflu05@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:03:30 +0100 Subject: [PATCH] handle report previewing errors (#6709) --- .../TemplateEditor/PdfPreview/PdfPreview.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/components/editors/TemplateEditor/PdfPreview/PdfPreview.tsx b/src/frontend/src/components/editors/TemplateEditor/PdfPreview/PdfPreview.tsx index 5711756704..a732935a93 100644 --- a/src/frontend/src/components/editors/TemplateEditor/PdfPreview/PdfPreview.tsx +++ b/src/frontend/src/components/editors/TemplateEditor/PdfPreview/PdfPreview.tsx @@ -1,4 +1,4 @@ -import { Trans } from '@lingui/macro'; +import { Trans, t } from '@lingui/macro'; import { forwardRef, useImperativeHandle, useState } from 'react'; import { api } from '../../../../App'; @@ -36,7 +36,16 @@ export const PdfPreviewComponent: PreviewAreaComponent = forwardRef( ); if (preview.status !== 200) { - if (preview.data?.non_field_errors) { + if (templateType === 'report') { + let data; + try { + data = JSON.parse(await preview.data.text()); + } catch (err) { + throw new Error(t`Failed to parse error response from server.`); + } + + throw new Error(data.detail?.join(', ')); + } else if (preview.data?.non_field_errors) { throw new Error(preview.data?.non_field_errors.join(', ')); }