Better handling of 404 errors when loading from backend (#608)
This commit is contained in:
parent
ead9aab888
commit
fc341c3763
@ -158,13 +158,18 @@ export async function exportToBackend(
|
|||||||
export async function importFromBackend(id: string | null) {
|
export async function importFromBackend(id: string | null) {
|
||||||
let elements: readonly ExcalidrawElement[] = [];
|
let elements: readonly ExcalidrawElement[] = [];
|
||||||
let appState: AppState = getDefaultAppState();
|
let appState: AppState = getDefaultAppState();
|
||||||
const response = await fetch(`${BACKEND_GET}${id}.json`).then(data =>
|
const data = await fetch(`${BACKEND_GET}${id}.json`)
|
||||||
data.clone().json(),
|
.then(response => {
|
||||||
);
|
if (!response.ok) {
|
||||||
if (response != null) {
|
window.alert(i18n.t("alerts.importBackendFailed"));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
})
|
||||||
|
.then(response => response.clone().json());
|
||||||
|
if (data != null) {
|
||||||
try {
|
try {
|
||||||
elements = response.elements || elements;
|
elements = data.elements || elements;
|
||||||
appState = response.appState || appState;
|
appState = data.appState || appState;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
window.alert(t("alerts.importBackendFailed"));
|
window.alert(t("alerts.importBackendFailed"));
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user