handle report previewing errors (#6709)

This commit is contained in:
Lukas 2024-03-14 13:03:30 +01:00 committed by GitHub
parent 267ff67f05
commit ec5ff6408d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(', '));
}