2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 19:46:46 +00:00

TemplateEditor: Handle fetch error (#8260)

* TemplateEditor: Handle fetch error

- Handle error condition where template cannot be loaded from server

* Remove test code
This commit is contained in:
Oliver 2024-10-09 16:13:32 +11:00 committed by GitHub
parent 13ef30768f
commit e8c72d60b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,7 +9,11 @@ import {
Tabs Tabs
} from '@mantine/core'; } from '@mantine/core';
import { openConfirmModal } from '@mantine/modals'; import { openConfirmModal } from '@mantine/modals';
import { notifications, showNotification } from '@mantine/notifications'; import {
hideNotification,
notifications,
showNotification
} from '@mantine/notifications';
import { import {
IconAlertTriangle, IconAlertTriangle,
IconDeviceFloppy, IconDeviceFloppy,
@ -126,9 +130,24 @@ export function TemplateEditor(props: Readonly<TemplateEditorProps>) {
api.get(templateUrl).then((response: any) => { api.get(templateUrl).then((response: any) => {
if (response.data?.template) { if (response.data?.template) {
api.get(response.data.template).then((res) => { api
.get(response.data.template)
.then((res) => {
codeRef.current = res.data; codeRef.current = res.data;
loadCodeToEditor(res.data); loadCodeToEditor(res.data);
})
.catch(() => {
console.error(
`ERR: Could not load template from ${response.data.template}`
);
codeRef.current = undefined;
hideNotification('template-load-error');
showNotification({
id: 'template-load-error',
title: t`Error`,
message: t`Could not load the template from the server.`,
color: 'red'
});
}); });
} }
}); });