From 553f057dbfcdd7bb45888de8757919af8a6e1648 Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Wed, 9 Sep 2020 16:54:31 +0200 Subject: [PATCH] fix: better handle import errors --- .../directives/views/accountMenu.ts | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/directives/views/accountMenu.ts b/app/assets/javascripts/directives/views/accountMenu.ts index 1695a0e27fc..955c3b4cdf7 100644 --- a/app/assets/javascripts/directives/views/accountMenu.ts +++ b/app/assets/javascripts/directives/views/accountMenu.ts @@ -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; @@ -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 ); @@ -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); }