Skip to content

Commit

Permalink
handle report previewing errors (inventree#6709)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolflu05 authored Mar 14, 2024
1 parent 267ff67 commit ec5ff64
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(', '));
}

Expand Down

0 comments on commit ec5ff64

Please sign in to comment.