Allow opening empty excalidraw file (#1348)
* allow openning empty file * correctly throw error * fix error handling * switch back to error objects Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
70e7dd6e3b
commit
0a284adc18
@ -92,7 +92,7 @@ export const actionLoadScene = register({
|
||||
updateData({ elements: elements, appState: appState });
|
||||
})
|
||||
.catch((error) => {
|
||||
updateData({ error: error });
|
||||
updateData({ error: error.message });
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
@ -2358,7 +2358,7 @@ export class App extends React.Component<any, AppState> {
|
||||
}),
|
||||
)
|
||||
.catch((error) => {
|
||||
this.setState({ isLoading: false, errorMessage: error });
|
||||
this.setState({ isLoading: false, errorMessage: error.message });
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { getDefaultAppState } from "../appState";
|
||||
import { DataState } from "./types";
|
||||
import { restore } from "./restore";
|
||||
import { t } from "../i18n";
|
||||
|
||||
@ -16,7 +15,7 @@ export async function loadFromBlob(blob: any) {
|
||||
elements = data.elements || [];
|
||||
appState = { ...defaultAppState, ...data.appState };
|
||||
} catch {
|
||||
// Do nothing because elements array is already empty
|
||||
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
||||
}
|
||||
return { elements, appState };
|
||||
};
|
||||
@ -38,11 +37,7 @@ export async function loadFromBlob(blob: any) {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const { elements, appState } = updateAppState(contents);
|
||||
if (!elements.length) {
|
||||
return Promise.reject(t("alerts.couldNotLoadInvalidFile"));
|
||||
}
|
||||
return new Promise<DataState>((resolve) => {
|
||||
resolve(restore(elements, appState, { scrollToContent: true }));
|
||||
});
|
||||
return restore(elements, appState, { scrollToContent: true });
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user