From 4a3ffe07e8e1bc8b3b3e9b3ca15dbc4463245b51 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 13 Jan 2023 14:01:47 -0800 Subject: [PATCH] sendToGroup: 404 from multi_recipient endpoint now treated differently --- ts/textsecure/Errors.ts | 2 ++ ts/util/sendToGroup.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ts/textsecure/Errors.ts b/ts/textsecure/Errors.ts index 5a57b1b446f7..6dfd832b63e6 100644 --- a/ts/textsecure/Errors.ts +++ b/ts/textsecure/Errors.ts @@ -303,4 +303,6 @@ export class UnregisteredUserError extends Error { export class ConnectTimeoutError extends Error {} +export class UnknownRecipientError extends Error {} + export class WarnOnlyError extends Error {} diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index 0495db7758f8..634f0e70e0db 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -36,6 +36,7 @@ import { ConnectTimeoutError, OutgoingIdentityKeyError, SendMessageProtoError, + UnknownRecipientError, UnregisteredUserError, } from '../textsecure/Errors'; import type { HTTPError } from '../textsecure/Errors'; @@ -63,6 +64,7 @@ import * as log from '../logging/log'; import { GLOBAL_ZONE } from '../SignalProtocolStore'; import { waitForAll } from './waitForAll'; +const UNKNOWN_RECIPIENT = 404; const ERROR_EXPIRED_OR_MISSING_DEVICES = 409; const ERROR_STALE_DEVICES = 410; @@ -564,6 +566,10 @@ export async function sendToGroupViaSenderKey(options: { ); } } catch (error) { + if (error.code === UNKNOWN_RECIPIENT) { + throw new UnknownRecipientError(); + } + if (error.code === ERROR_EXPIRED_OR_MISSING_DEVICES) { await handle409Response(logId, error); @@ -758,6 +764,11 @@ export function _shouldFailSend(error: unknown, logId: string): boolean { log.error(`_shouldFailSend/${logId}: ${message}`); }; + // We need to fail over to a normal send if multi_recipient/ endpoint returns 404 + if (error instanceof UnknownRecipientError) { + return false; + } + if ( error instanceof LibSignalErrorBase && error.code === ErrorCode.UntrustedIdentity @@ -794,7 +805,7 @@ export function _shouldFailSend(error: unknown, logId: string): boolean { } if (error.code === 404) { - logError('Missing user or endpoint error, failing.'); + logError('Failed to fetch metadata before send, failing.'); return true; }