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:
Kostas Bariotis 2020-04-10 10:58:09 +01:00 committed by GitHub
parent 70e7dd6e3b
commit 0a284adc18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 10 deletions

View File

@ -92,7 +92,7 @@ export const actionLoadScene = register({
updateData({ elements: elements, appState: appState });
})
.catch((error) => {
updateData({ error: error });
updateData({ error: error.message });
});
}}
/>

View File

@ -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({

View File

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