From 09d279dd93d942a382d939a0f7bb263b5538a097 Mon Sep 17 00:00:00 2001 From: Maxim Shishmarev Date: Mon, 5 Aug 2019 11:14:19 +1000 Subject: [PATCH] Show correct error on incorrect timestamp --- js/modules/loki_message_api.js | 3 +++ js/modules/loki_rpc.js | 6 ++++++ libtextsecure/errors.js | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index 5c98cc00e..3abf48637 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -240,6 +240,9 @@ class LokiMessageAPI { throw e; } else if (e instanceof textsecure.NotFoundError) { // TODO: Handle resolution error + } else if (e instanceof textsecure.TimestampError) { + log.warn('Timestamp is invalid'); + throw e; } else if (e instanceof textsecure.HTTPError) { // TODO: Handle working connection but error response const body = await e.response.text(); diff --git a/js/modules/loki_rpc.js b/js/modules/loki_rpc.js index 43c9eb060..ae5daa351 100644 --- a/js/modules/loki_rpc.js +++ b/js/modules/loki_rpc.js @@ -77,6 +77,12 @@ const fetch = async (url, options = {}) => { throw new textsecure.WrongDifficultyError(difficulty); } + if (response.status === 406) { + throw new textsecure.TimestampError( + 'Invalid Timestamp (check your clock)' + ); + } + if (!response.ok) { throw new textsecure.HTTPError('Loki_rpc error', response); } diff --git a/libtextsecure/errors.js b/libtextsecure/errors.js index c0ec618f1..c97d21fe3 100644 --- a/libtextsecure/errors.js +++ b/libtextsecure/errors.js @@ -263,6 +263,16 @@ } } + function TimestampError(message) { + this.name = 'TimeStampError'; + + ReplayableError.call(this, { + name: 'TimestampError', + message, + }); + } + inherit(ReplayableError, TimestampError); + window.textsecure.UnregisteredUserError = UnregisteredUserError; window.textsecure.SendMessageNetworkError = SendMessageNetworkError; window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError; @@ -281,4 +291,5 @@ window.textsecure.NotFoundError = NotFoundError; window.textsecure.WrongSwarmError = WrongSwarmError; window.textsecure.WrongDifficultyError = WrongDifficultyError; + window.textsecure.TimestampError = TimestampError; })();