Clean up when new key backup version fails to backup

If creating a new key backup version succeeds but backing up to it fails, delete
the version to avoid surprises. In addition, this converts the creation of a new
key backup to async / await style.

Signed-off-by: J. Ryan Stinnett <jryans@gmail.com>
pull/21833/head
J. Ryan Stinnett 2018-12-13 12:10:08 +00:00
parent 1c4621c98e
commit 2b14f2af5c
1 changed files with 16 additions and 8 deletions

View File

@ -92,25 +92,33 @@ export default React.createClass({
});
},
_createBackup: function() {
_createBackup: async function() {
this.setState({
phase: PHASE_BACKINGUP,
error: null,
});
this._createBackupPromise = MatrixClientPeg.get().createKeyBackupVersion(
this._keyBackupInfo,
).then((info) => {
return MatrixClientPeg.get().backupAllGroupSessions(info.version);
}).then(() => {
let info;
try {
info = await MatrixClientPeg.get().createKeyBackupVersion(
this._keyBackupInfo,
);
await MatrixClientPeg.get().backupAllGroupSessions(info.version);
this.setState({
phase: PHASE_DONE,
});
}).catch(e => {
} catch (e) {
console.log("Error creating key backup", e);
// TODO: If creating a version succeeds, but backup fails, should we
// delete the version, disable backup, or do nothing? If we just
// disable without deleting, we'll enable on next app reload since
// it is trusted.
if (info) {
MatrixClientPeg.get().deleteKeyBackupVersion(info.version);
}
this.setState({
error: e,
});
});
}
},
_onCancel: function() {