diff --git a/ts/background.ts b/ts/background.ts index c815ae42ca0d..ca21ef11540d 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -1311,7 +1311,8 @@ export async function startApp(): Promise { return; } - log.warn('background: remote expiration detected, disabling reconnects'); + log.error('background: remote expiration detected, disabling reconnects'); + drop(window.storage.put('remoteBuildExpiration', Date.now())); drop(server?.onRemoteExpiration()); remotelyExpired = true; }); diff --git a/ts/textsecure/SocketManager.ts b/ts/textsecure/SocketManager.ts index c77eb9f03502..44a83028fae0 100644 --- a/ts/textsecure/SocketManager.ts +++ b/ts/textsecure/SocketManager.ts @@ -1,7 +1,11 @@ // Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import type { Net } from '@signalapp/libsignal-client'; +import { + ErrorCode, + LibSignalErrorBase, + type Net, +} from '@signalapp/libsignal-client'; import URL from 'url'; import type { RequestInit, Response } from 'node-fetch'; import { Headers } from 'node-fetch'; @@ -278,7 +282,7 @@ export class SocketManager extends EventListener { const { code } = error; if (code === 401 || code === 403) { - this.emit('authError', error); + this.emit('authError'); return; } @@ -292,6 +296,18 @@ export class SocketManager extends EventListener { } } else if (error instanceof ConnectTimeoutError) { this.markOffline(); + } else if ( + error instanceof LibSignalErrorBase && + error.code === ErrorCode.DeviceDelinked + ) { + this.emit('authError'); + return; + } else if ( + error instanceof LibSignalErrorBase && + error.code === ErrorCode.AppExpired + ) { + window.Whisper.events.trigger('httpResponse499'); + return; } drop(reconnect()); @@ -931,10 +947,7 @@ export class SocketManager extends EventListener { // EventEmitter types - public override on( - type: 'authError', - callback: (error: HTTPError) => void - ): this; + public override on(type: 'authError', callback: () => void): this; public override on(type: 'statusChange', callback: () => void): this; public override on(type: 'online', callback: () => void): this; public override on(type: 'offline', callback: () => void): this; @@ -951,7 +964,7 @@ export class SocketManager extends EventListener { return super.on(type, listener); } - public override emit(type: 'authError', error: HTTPError): boolean; + public override emit(type: 'authError'): boolean; public override emit(type: 'statusChange'): boolean; public override emit(type: 'online'): boolean; public override emit(type: 'offline'): boolean; diff --git a/ts/textsecure/Utils.ts b/ts/textsecure/Utils.ts index bb7b73dfc905..9dd44d65c1fb 100644 --- a/ts/textsecure/Utils.ts +++ b/ts/textsecure/Utils.ts @@ -1,13 +1,10 @@ // Copyright 2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import * as log from '../logging/log'; import type { HTTPError } from './Errors'; export async function handleStatusCode(status: number): Promise { if (status === 499) { - log.error('Got 499 from Signal Server. Build is expired.'); - await window.storage.put('remoteBuildExpiration', Date.now()); window.Whisper.events.trigger('httpResponse499'); } }