Translate errors before rejecting in SendMessage

This commit is contained in:
Fedor Indutny 2021-07-19 18:10:09 -07:00 committed by GitHub
parent c4a09b7507
commit 31989a7706
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 99 additions and 40 deletions

View file

@ -59,7 +59,8 @@ import {
GroupCredentialsType,
GroupLogResponseType,
} from './textsecure/WebAPI';
import MessageSender, { CallbackResultType } from './textsecure/SendMessage';
import MessageSender from './textsecure/SendMessage';
import { CallbackResultType } from './textsecure/Types.d';
import { CURRENT_SCHEMA_VERSION as MAX_MESSAGE_SCHEMA } from '../js/modules/types/message';
import { ConversationModel } from './models/conversations';
import { getGroupSizeHardLimit } from './groups/limits';

View file

@ -16,7 +16,8 @@ import {
import { AttachmentType } from '../types/Attachment';
import { CallMode, CallHistoryDetailsType } from '../types/Calling';
import * as Stickers from '../types/Stickers';
import { CallbackResultType, GroupV2InfoType } from '../textsecure/SendMessage';
import { GroupV2InfoType } from '../textsecure/SendMessage';
import { CallbackResultType } from '../textsecure/Types.d';
import { ConversationType } from '../state/ducks/conversations';
import {
AvatarColorType,

View file

@ -23,12 +23,13 @@ import {
Contact as SmartMessageDetailContact,
} from '../state/smart/MessageDetail';
import { getCallingNotificationText } from '../util/callingNotification';
import { CallbackResultType } from '../textsecure/SendMessage';
import {
ProcessedDataMessage,
ProcessedQuote,
ProcessedUnidentifiedDeliveryStatus,
CallbackResultType,
} from '../textsecure/Types.d';
import { SendMessageProtoError } from '../textsecure/Errors';
import * as expirationTimer from '../util/expirationTimer';
import { ReactionType } from '../types/Reactions';
@ -1555,7 +1556,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
| { success: true; value: CallbackResultType }
| {
success: false;
value: CustomError | CallbackResultType;
value: CustomError | SendMessageProtoError;
};
try {
const value = await (promise as Promise<CallbackResultType>);

View file

@ -6,9 +6,8 @@ import * as sinon from 'sinon';
import { setup as setupI18n } from '../../../js/modules/i18n';
import enMessages from '../../../_locales/en/messages.json';
import { SendStatus } from '../../messages/MessageSendState';
import MessageSender, {
CallbackResultType,
} from '../../textsecure/SendMessage';
import MessageSender from '../../textsecure/SendMessage';
import { CallbackResultType } from '../../textsecure/Types.d';
import type { StorageAccessType } from '../../types/Storage.d';
import { SignalService as Proto } from '../../protobuf';

View file

@ -6,6 +6,8 @@
import { parseRetryAfter } from '../util/parseRetryAfter';
import { CallbackResultType } from './Types.d';
function appendStack(newError: Error, originalError: Error) {
// eslint-disable-next-line no-param-reassign
newError.stack += `\nOriginal stack:\n${originalError.stack}`;
@ -137,6 +139,61 @@ export class SendMessageChallengeError extends ReplayableError {
}
}
export class SendMessageProtoError extends Error implements CallbackResultType {
public readonly successfulIdentifiers?: Array<string>;
public readonly failoverIdentifiers?: Array<string>;
public readonly errors?: CallbackResultType['errors'];
public readonly unidentifiedDeliveries?: Array<string>;
public readonly dataMessage?: ArrayBuffer;
// Fields necesary for send log save
public readonly contentHint?: number;
public readonly contentProto?: Uint8Array;
public readonly timestamp?: number;
public readonly recipients?: Record<string, Array<number>>;
constructor({
successfulIdentifiers,
failoverIdentifiers,
errors,
unidentifiedDeliveries,
dataMessage,
contentHint,
contentProto,
timestamp,
recipients,
}: CallbackResultType) {
super(`SendMessageProtoError: ${SendMessageProtoError.getMessage(errors)}`);
this.successfulIdentifiers = successfulIdentifiers;
this.failoverIdentifiers = failoverIdentifiers;
this.errors = errors;
this.unidentifiedDeliveries = unidentifiedDeliveries;
this.dataMessage = dataMessage;
this.contentHint = contentHint;
this.contentProto = contentProto;
this.timestamp = timestamp;
this.recipients = recipients;
}
protected static getMessage(errors: CallbackResultType['errors']): string {
if (!errors) {
return 'No errors';
}
return errors
.map(error => (error.stackForLog ? error.stackForLog : error.toString()))
.join(', ');
}
}
export class SignedPreKeyRotationError extends ReplayableError {
constructor() {
super({

View file

@ -23,12 +23,7 @@ import {
} from '@signalapp/signal-client';
import { WebAPIType } from './WebAPI';
import {
CallbackResultType,
SendMetadataType,
SendOptionsType,
CustomError,
} from './SendMessage';
import { SendMetadataType, SendOptionsType } from './SendMessage';
import {
OutgoingIdentityKeyError,
OutgoingMessageError,
@ -36,6 +31,7 @@ import {
SendMessageChallengeError,
UnregisteredUserError,
} from './Errors';
import { CallbackResultType, CustomError } from './Types.d';
import { isValidNumber } from '../types/PhoneNumber';
import { Sessions, IdentityKeys } from '../LibSignalStores';
import { typedArrayToArrayBuffer as toArrayBuffer } from '../Crypto';

View file

@ -30,6 +30,7 @@ import {
WebAPIType,
} from './WebAPI';
import createTaskWithTimeout from './TaskWithTimeout';
import { CallbackResultType } from './Types.d';
import OutgoingMessage, {
SerializedCertificateType,
SendLogCallbackType,
@ -46,7 +47,11 @@ import {
StorageServiceCallOptionsType,
StorageServiceCredentials,
} from '../textsecure.d';
import { MessageError, SignedPreKeyRotationError } from './Errors';
import {
MessageError,
SignedPreKeyRotationError,
SendMessageProtoError,
} from './Errors';
import { BodyRangesType } from '../types/Util';
import {
LinkPreviewImage,
@ -72,25 +77,6 @@ export type SendOptionsType = {
online?: boolean;
};
export type CustomError = Error & {
identifier?: string;
number?: string;
};
export type CallbackResultType = {
successfulIdentifiers?: Array<string>;
failoverIdentifiers?: Array<string>;
errors?: Array<CustomError>;
unidentifiedDeliveries?: Array<string>;
dataMessage?: ArrayBuffer;
// Fields necesary for send log save
contentHint?: number;
contentProto?: Uint8Array;
timestamp?: number;
recipients?: Record<string, Array<number>>;
};
type PreviewType = {
url: string;
title: string;
@ -826,7 +812,7 @@ export default class MessageSender {
callback: (res: CallbackResultType) => {
res.dataMessage = message.toArrayBuffer();
if (res.errors && res.errors.length > 0) {
reject(res);
reject(new SendMessageProtoError(res));
} else {
resolve(res);
}
@ -906,7 +892,7 @@ export default class MessageSender {
return new Promise((resolve, reject) => {
const callback = (result: CallbackResultType) => {
if (result && result.errors && result.errors.length > 0) {
reject(result);
reject(new SendMessageProtoError(result));
return;
}
@ -942,7 +928,7 @@ export default class MessageSender {
return new Promise((resolve, reject) => {
const callback = (res: CallbackResultType) => {
if (res && res.errors && res.errors.length > 0) {
reject(res);
reject(new SendMessageProtoError(res));
} else {
resolve(res);
}
@ -1839,7 +1825,7 @@ export default class MessageSender {
const callback = (res: CallbackResultType) => {
res.dataMessage = dataMessage;
if (res.errors && res.errors.length > 0) {
reject(res);
reject(new SendMessageProtoError(res));
} else {
resolve(res);
}

View file

@ -208,3 +208,22 @@ export type ProcessedSent = Omit<
export type ProcessedSyncMessage = Omit<Proto.ISyncMessage, 'sent'> & {
sent?: ProcessedSent;
};
export type CustomError = Error & {
identifier?: string;
number?: string;
};
export interface CallbackResultType {
successfulIdentifiers?: Array<string>;
failoverIdentifiers?: Array<string>;
errors?: Array<CustomError>;
unidentifiedDeliveries?: Array<string>;
dataMessage?: ArrayBuffer;
// Fields necesary for send log save
contentHint?: number;
contentProto?: Uint8Array;
timestamp?: number;
recipients?: Record<string, Array<number>>;
}

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import { isNumber } from 'lodash';
import { CallbackResultType } from '../textsecure/SendMessage';
import { CallbackResultType } from '../textsecure/Types.d';
import dataInterface from '../sql/Client';
const { insertSentProto } = dataInterface;

View file

@ -22,13 +22,12 @@ import { isEnabled } from '../RemoteConfig';
import { isOlderThan } from './timestamp';
import {
CallbackResultType,
GroupSendOptionsType,
SendOptionsType,
} from '../textsecure/SendMessage';
import { IdentityKeys, SenderKeys, Sessions } from '../LibSignalStores';
import { ConversationModel } from '../models/conversations';
import { DeviceType } from '../textsecure/Types.d';
import { DeviceType, CallbackResultType } from '../textsecure/Types.d';
import { getKeysForIdentifier } from '../textsecure/getKeysForIdentifier';
import { ConversationAttributesType } from '../model-types.d';
import {