Skip to content

Commit

Permalink
fix: better handle import errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Sep 10, 2020
1 parent c3ad129 commit 553f057
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions app/assets/javascripts/directives/views/accountMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,11 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
if (!data) {
return;
}
if (data.auth_params || data.keyParams) {
const version = data.keyParams?.version || data.auth_params?.version;
if (!this.application!.protocolService!.supportedVersions().includes(version)) {
if (data.version || data.auth_params || data.keyParams) {
const version = data.version || data.keyParams?.version || data.auth_params?.version;
if (
!this.application!.protocolService!.supportedVersions().includes(version)
) {
await this.setState({ importData: null });
alertDialog({ text: STRING_UNSUPPORTED_BACKUP_FILE_VERSION });
return;
Expand Down Expand Up @@ -419,12 +421,19 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
loading: true
}
});
const errorCount = await this.importJSONData(data, password);
const result = await this.application!.importData(
data,
password
);
this.setState({
importData: null
});
if (errorCount > 0) {
const message = StringImportError(errorCount);
if ('error' in result) {
this.application!.alertService!.alert(
result.error
);
} else if (result.errorCount) {
const message = StringImportError(result.errorCount);
this.application!.alertService!.alert(
message
);
Expand All @@ -435,14 +444,6 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
}
}

async importJSONData(data: BackupFile, password?: string) {
const { errorCount } = await this.application!.importData(
data,
password
);
return errorCount;
}

async downloadDataArchive() {
this.application!.getArchiveService().downloadBackup(this.getState().mutable.backupEncrypted);
}
Expand Down

0 comments on commit 553f057

Please sign in to comment.