Handle invalid file on import (#7960)

* handle invalid file on import

* update

* error msg update

* Update frontend/src/HomePage/HomePage.jsx

Co-authored-by: Midhun G S <gsmithun4@gmail.com>

---------

Co-authored-by: Midhun G S <gsmithun4@gmail.com>
This commit is contained in:
Anantshree Chandola 2023-10-19 11:14:37 +05:30 committed by GitHub
parent 56085460c4
commit 4b2f9af794
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -209,11 +209,18 @@ class HomePageComponent extends React.Component {
fileReader.readAsText(file, 'UTF-8');
fileReader.onload = (event) => {
const result = event.target.result;
const fileContent = JSON.parse(result);
let fileContent;
try {
fileContent = JSON.parse(result);
} catch (parseError) {
toast.error(`Could not import: ${parseError}`);
return;
}
this.setState({ fileContent, fileName, showImportAppModal: true });
};
fileReader.onerror = (error) => {
throw new Error(`Could not import the app: ${error}`);
toast.error(`Could not import the app: ${error}`);
return;
};
event.target.value = null;
} catch (error) {