diff --git a/js/libtextsecure.js b/js/libtextsecure.js index eea7ce22..5895e0f5 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -102,7 +102,17 @@ MessageError.prototype = new ReplayableError(); MessageError.prototype.constructor = MessageError; + function UnregisteredUserError(number, httpError) { + this.name = 'UnregisteredUserError'; + this.number = number; + this.code = httpError.code; + this.message = httpError.message; + this.stack = httpError.stack; + } + UnregisteredUserError.prototype = new Error(); + UnregisteredUserError.prototype.constructor = UnregisteredUserError; + window.textsecure.UnregisteredUserError = UnregisteredUserError; window.textsecure.SendMessageNetworkError = SendMessageNetworkError; window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError; window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError; @@ -38570,9 +38580,13 @@ OutgoingMessage.prototype = { transmitMessage: function(number, jsonData, timestamp) { return this.server.sendMessages(number, jsonData, timestamp).catch(function(e) { - if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410 && e.code !== 404)) { + if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410)) { // 409 and 410 should bubble and be handled by doSendMessage + // 404 should throw UnregisteredUserError // all other network errors can be retried later. + if (e.code === 404) { + throw new textsecure.UnregisteredUserError(number, e); + } throw new textsecure.SendMessageNetworkError(number, jsonData, e, timestamp); } throw e; diff --git a/libtextsecure/errors.js b/libtextsecure/errors.js index 27a0eebc..e30f1cad 100644 --- a/libtextsecure/errors.js +++ b/libtextsecure/errors.js @@ -101,7 +101,17 @@ MessageError.prototype = new ReplayableError(); MessageError.prototype.constructor = MessageError; + function UnregisteredUserError(number, httpError) { + this.name = 'UnregisteredUserError'; + this.number = number; + this.code = httpError.code; + this.message = httpError.message; + this.stack = httpError.stack; + } + UnregisteredUserError.prototype = new Error(); + UnregisteredUserError.prototype.constructor = UnregisteredUserError; + window.textsecure.UnregisteredUserError = UnregisteredUserError; window.textsecure.SendMessageNetworkError = SendMessageNetworkError; window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError; window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError; diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 316eb299..0444fb12 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -79,9 +79,13 @@ OutgoingMessage.prototype = { transmitMessage: function(number, jsonData, timestamp) { return this.server.sendMessages(number, jsonData, timestamp).catch(function(e) { - if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410 && e.code !== 404)) { + if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410)) { // 409 and 410 should bubble and be handled by doSendMessage + // 404 should throw UnregisteredUserError // all other network errors can be retried later. + if (e.code === 404) { + throw new textsecure.UnregisteredUserError(number, e); + } throw new textsecure.SendMessageNetworkError(number, jsonData, e, timestamp); } throw e;