sendToGroup: Don't fail send if we get 401 from multi_recipient/ request

This commit is contained in:
Scott Nonnenberg 2023-01-20 16:50:34 -08:00 committed by GitHub
parent b5947e0ef1
commit 7c1f186c05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -15,12 +15,14 @@ import type { DeviceType } from '../../textsecure/Types.d';
import {
ConnectTimeoutError,
HTTPError,
IncorrectSenderKeyAuthError,
MessageError,
OutgoingIdentityKeyError,
OutgoingMessageError,
SendMessageChallengeError,
SendMessageNetworkError,
SendMessageProtoError,
UnknownRecipientError,
UnregisteredUserError,
} from '../../textsecure/Errors';
@ -219,6 +221,16 @@ describe('sendToGroup', () => {
assert.isFalse(_shouldFailSend(error, 'testing generic 204'));
});
it('returns false for specific errors', () => {
const unknownRecipient = new UnknownRecipientError();
assert.isFalse(
_shouldFailSend(unknownRecipient, 'testing unknown recipient')
);
const incorrectAuth = new IncorrectSenderKeyAuthError();
assert.isFalse(_shouldFailSend(incorrectAuth, 'testing incorrect auth'));
});
it('returns true for a specified error codes', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const error: any = new Error('generic');

View file

@ -305,4 +305,6 @@ export class ConnectTimeoutError extends Error {}
export class UnknownRecipientError extends Error {}
export class IncorrectSenderKeyAuthError extends Error {}
export class WarnOnlyError extends Error {}

View file

@ -34,6 +34,7 @@ import type {
} from '../textsecure/SendMessage';
import {
ConnectTimeoutError,
IncorrectSenderKeyAuthError,
OutgoingIdentityKeyError,
SendMessageProtoError,
UnknownRecipientError,
@ -65,6 +66,7 @@ import { GLOBAL_ZONE } from '../SignalProtocolStore';
import { waitForAll } from './waitForAll';
const UNKNOWN_RECIPIENT = 404;
const INCORRECT_AUTH_KEY = 401;
const ERROR_EXPIRED_OR_MISSING_DEVICES = 409;
const ERROR_STALE_DEVICES = 410;
@ -569,6 +571,9 @@ export async function sendToGroupViaSenderKey(options: {
if (error.code === UNKNOWN_RECIPIENT) {
throw new UnknownRecipientError();
}
if (error.code === INCORRECT_AUTH_KEY) {
throw new IncorrectSenderKeyAuthError();
}
if (error.code === ERROR_EXPIRED_OR_MISSING_DEVICES) {
await handle409Response(logId, error);
@ -764,10 +769,13 @@ 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
// We need to fail over to a normal send if multi_recipient/ endpoint returns 404 or 401
if (error instanceof UnknownRecipientError) {
return false;
}
if (error instanceof IncorrectSenderKeyAuthError) {
return false;
}
if (
error instanceof LibSignalErrorBase &&