From 01e85b68efc1a2d5db4f13d0828c7a7f04870b7a Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 21 Oct 2015 12:49:06 -0700 Subject: [PATCH] Handle exceptions when fetching keys for devices It's rare that we get in a state where we have a device record without a session, but we should handle errors gracefully in that case. Catch them and register them, except for identity key errors which are registered in handleResult. // FREEBIE fixup error handling // FREEBIE --- js/libtextsecure.js | 12 ++++++++++-- libtextsecure/outgoing_message.js | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index fd0fbd5625..109e56d119 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -39745,8 +39745,16 @@ OutgoingMessage.prototype = { return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) { return Promise.all(devicesForNumber.map(function(device) { return textsecure.protocol_wrapper.hasOpenSession(device.encodedNumber).then(function(result) { - if (!result) - return this.getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]); + if (!result) { + return this.getKeysForNumber(number, + [parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])] + ).catch(function(error) { + if (error.name !== 'OutgoingIdentityKeyError') { + this.registerError(number, "Failed to retreive new device keys for " + device.encodedNumber, error); + } + return Promise.reject(); + }.bind(this)); + } }.bind(this)); }.bind(this))).then(function() { return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) { diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 39633b99e7..b2b32edab2 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -114,8 +114,16 @@ OutgoingMessage.prototype = { return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) { return Promise.all(devicesForNumber.map(function(device) { return textsecure.protocol_wrapper.hasOpenSession(device.encodedNumber).then(function(result) { - if (!result) - return this.getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]); + if (!result) { + return this.getKeysForNumber(number, + [parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])] + ).catch(function(error) { + if (error.name !== 'OutgoingIdentityKeyError') { + this.registerError(number, "Failed to retreive new device keys for " + device.encodedNumber, error); + } + return Promise.reject(); + }.bind(this)); + } }.bind(this)); }.bind(this))).then(function() { return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {