UI: Catch TypeError when uploading a config file and set appropriate error message

This error message is different from the one in sendConfigToServer()
since this one only checks for 3 things (metadata.encrypted,
configuration, credentials). The one in sendConfigToServer() tries
importing the whole configuration.
This commit is contained in:
Shreya Malviya 2022-08-03 17:43:09 +05:30
parent b4c9f0df9e
commit 3d00460f98
1 changed files with 14 additions and 3 deletions

View File

@ -142,9 +142,20 @@ const ConfigImportModal = (props: Props) => {
setErrorMessage('File is not in a valid json format');
return
}
setConfigEncrypted(importContents['metadata']['encrypted']);
setConfigContents(importContents['configuration']);
setConfigCredentials(importContents['credentials']);
try {
setConfigEncrypted(importContents['metadata']['encrypted']);
setConfigContents(importContents['configuration']);
setConfigCredentials(importContents['credentials']);
} catch (e) {
if (e instanceof TypeError) {
setErrorMessage('Missing required fields, configuration file is most '
+ 'likely from an old version')
}
else {
throw e;
}
}
};
reader.readAsText(event.target.files[0]);
}