Translate errors before rejecting in SendMessage
This commit is contained in:
parent
c4a09b7507
commit
31989a7706
10 changed files with 99 additions and 40 deletions
|
@ -59,7 +59,8 @@ import {
|
||||||
GroupCredentialsType,
|
GroupCredentialsType,
|
||||||
GroupLogResponseType,
|
GroupLogResponseType,
|
||||||
} from './textsecure/WebAPI';
|
} 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 { CURRENT_SCHEMA_VERSION as MAX_MESSAGE_SCHEMA } from '../js/modules/types/message';
|
||||||
import { ConversationModel } from './models/conversations';
|
import { ConversationModel } from './models/conversations';
|
||||||
import { getGroupSizeHardLimit } from './groups/limits';
|
import { getGroupSizeHardLimit } from './groups/limits';
|
||||||
|
|
|
@ -16,7 +16,8 @@ import {
|
||||||
import { AttachmentType } from '../types/Attachment';
|
import { AttachmentType } from '../types/Attachment';
|
||||||
import { CallMode, CallHistoryDetailsType } from '../types/Calling';
|
import { CallMode, CallHistoryDetailsType } from '../types/Calling';
|
||||||
import * as Stickers from '../types/Stickers';
|
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 { ConversationType } from '../state/ducks/conversations';
|
||||||
import {
|
import {
|
||||||
AvatarColorType,
|
AvatarColorType,
|
||||||
|
|
|
@ -23,12 +23,13 @@ import {
|
||||||
Contact as SmartMessageDetailContact,
|
Contact as SmartMessageDetailContact,
|
||||||
} from '../state/smart/MessageDetail';
|
} from '../state/smart/MessageDetail';
|
||||||
import { getCallingNotificationText } from '../util/callingNotification';
|
import { getCallingNotificationText } from '../util/callingNotification';
|
||||||
import { CallbackResultType } from '../textsecure/SendMessage';
|
|
||||||
import {
|
import {
|
||||||
ProcessedDataMessage,
|
ProcessedDataMessage,
|
||||||
ProcessedQuote,
|
ProcessedQuote,
|
||||||
ProcessedUnidentifiedDeliveryStatus,
|
ProcessedUnidentifiedDeliveryStatus,
|
||||||
|
CallbackResultType,
|
||||||
} from '../textsecure/Types.d';
|
} from '../textsecure/Types.d';
|
||||||
|
import { SendMessageProtoError } from '../textsecure/Errors';
|
||||||
import * as expirationTimer from '../util/expirationTimer';
|
import * as expirationTimer from '../util/expirationTimer';
|
||||||
|
|
||||||
import { ReactionType } from '../types/Reactions';
|
import { ReactionType } from '../types/Reactions';
|
||||||
|
@ -1555,7 +1556,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
| { success: true; value: CallbackResultType }
|
| { success: true; value: CallbackResultType }
|
||||||
| {
|
| {
|
||||||
success: false;
|
success: false;
|
||||||
value: CustomError | CallbackResultType;
|
value: CustomError | SendMessageProtoError;
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const value = await (promise as Promise<CallbackResultType>);
|
const value = await (promise as Promise<CallbackResultType>);
|
||||||
|
|
|
@ -6,9 +6,8 @@ import * as sinon from 'sinon';
|
||||||
import { setup as setupI18n } from '../../../js/modules/i18n';
|
import { setup as setupI18n } from '../../../js/modules/i18n';
|
||||||
import enMessages from '../../../_locales/en/messages.json';
|
import enMessages from '../../../_locales/en/messages.json';
|
||||||
import { SendStatus } from '../../messages/MessageSendState';
|
import { SendStatus } from '../../messages/MessageSendState';
|
||||||
import MessageSender, {
|
import MessageSender from '../../textsecure/SendMessage';
|
||||||
CallbackResultType,
|
import { CallbackResultType } from '../../textsecure/Types.d';
|
||||||
} from '../../textsecure/SendMessage';
|
|
||||||
import type { StorageAccessType } from '../../types/Storage.d';
|
import type { StorageAccessType } from '../../types/Storage.d';
|
||||||
import { SignalService as Proto } from '../../protobuf';
|
import { SignalService as Proto } from '../../protobuf';
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
import { parseRetryAfter } from '../util/parseRetryAfter';
|
import { parseRetryAfter } from '../util/parseRetryAfter';
|
||||||
|
|
||||||
|
import { CallbackResultType } from './Types.d';
|
||||||
|
|
||||||
function appendStack(newError: Error, originalError: Error) {
|
function appendStack(newError: Error, originalError: Error) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
newError.stack += `\nOriginal stack:\n${originalError.stack}`;
|
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 {
|
export class SignedPreKeyRotationError extends ReplayableError {
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
|
|
|
@ -23,12 +23,7 @@ import {
|
||||||
} from '@signalapp/signal-client';
|
} from '@signalapp/signal-client';
|
||||||
|
|
||||||
import { WebAPIType } from './WebAPI';
|
import { WebAPIType } from './WebAPI';
|
||||||
import {
|
import { SendMetadataType, SendOptionsType } from './SendMessage';
|
||||||
CallbackResultType,
|
|
||||||
SendMetadataType,
|
|
||||||
SendOptionsType,
|
|
||||||
CustomError,
|
|
||||||
} from './SendMessage';
|
|
||||||
import {
|
import {
|
||||||
OutgoingIdentityKeyError,
|
OutgoingIdentityKeyError,
|
||||||
OutgoingMessageError,
|
OutgoingMessageError,
|
||||||
|
@ -36,6 +31,7 @@ import {
|
||||||
SendMessageChallengeError,
|
SendMessageChallengeError,
|
||||||
UnregisteredUserError,
|
UnregisteredUserError,
|
||||||
} from './Errors';
|
} from './Errors';
|
||||||
|
import { CallbackResultType, CustomError } from './Types.d';
|
||||||
import { isValidNumber } from '../types/PhoneNumber';
|
import { isValidNumber } from '../types/PhoneNumber';
|
||||||
import { Sessions, IdentityKeys } from '../LibSignalStores';
|
import { Sessions, IdentityKeys } from '../LibSignalStores';
|
||||||
import { typedArrayToArrayBuffer as toArrayBuffer } from '../Crypto';
|
import { typedArrayToArrayBuffer as toArrayBuffer } from '../Crypto';
|
||||||
|
|
|
@ -30,6 +30,7 @@ import {
|
||||||
WebAPIType,
|
WebAPIType,
|
||||||
} from './WebAPI';
|
} from './WebAPI';
|
||||||
import createTaskWithTimeout from './TaskWithTimeout';
|
import createTaskWithTimeout from './TaskWithTimeout';
|
||||||
|
import { CallbackResultType } from './Types.d';
|
||||||
import OutgoingMessage, {
|
import OutgoingMessage, {
|
||||||
SerializedCertificateType,
|
SerializedCertificateType,
|
||||||
SendLogCallbackType,
|
SendLogCallbackType,
|
||||||
|
@ -46,7 +47,11 @@ import {
|
||||||
StorageServiceCallOptionsType,
|
StorageServiceCallOptionsType,
|
||||||
StorageServiceCredentials,
|
StorageServiceCredentials,
|
||||||
} from '../textsecure.d';
|
} from '../textsecure.d';
|
||||||
import { MessageError, SignedPreKeyRotationError } from './Errors';
|
import {
|
||||||
|
MessageError,
|
||||||
|
SignedPreKeyRotationError,
|
||||||
|
SendMessageProtoError,
|
||||||
|
} from './Errors';
|
||||||
import { BodyRangesType } from '../types/Util';
|
import { BodyRangesType } from '../types/Util';
|
||||||
import {
|
import {
|
||||||
LinkPreviewImage,
|
LinkPreviewImage,
|
||||||
|
@ -72,25 +77,6 @@ export type SendOptionsType = {
|
||||||
online?: boolean;
|
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 = {
|
type PreviewType = {
|
||||||
url: string;
|
url: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -826,7 +812,7 @@ export default class MessageSender {
|
||||||
callback: (res: CallbackResultType) => {
|
callback: (res: CallbackResultType) => {
|
||||||
res.dataMessage = message.toArrayBuffer();
|
res.dataMessage = message.toArrayBuffer();
|
||||||
if (res.errors && res.errors.length > 0) {
|
if (res.errors && res.errors.length > 0) {
|
||||||
reject(res);
|
reject(new SendMessageProtoError(res));
|
||||||
} else {
|
} else {
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}
|
}
|
||||||
|
@ -906,7 +892,7 @@ export default class MessageSender {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const callback = (result: CallbackResultType) => {
|
const callback = (result: CallbackResultType) => {
|
||||||
if (result && result.errors && result.errors.length > 0) {
|
if (result && result.errors && result.errors.length > 0) {
|
||||||
reject(result);
|
reject(new SendMessageProtoError(result));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,7 +928,7 @@ export default class MessageSender {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const callback = (res: CallbackResultType) => {
|
const callback = (res: CallbackResultType) => {
|
||||||
if (res && res.errors && res.errors.length > 0) {
|
if (res && res.errors && res.errors.length > 0) {
|
||||||
reject(res);
|
reject(new SendMessageProtoError(res));
|
||||||
} else {
|
} else {
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}
|
}
|
||||||
|
@ -1839,7 +1825,7 @@ export default class MessageSender {
|
||||||
const callback = (res: CallbackResultType) => {
|
const callback = (res: CallbackResultType) => {
|
||||||
res.dataMessage = dataMessage;
|
res.dataMessage = dataMessage;
|
||||||
if (res.errors && res.errors.length > 0) {
|
if (res.errors && res.errors.length > 0) {
|
||||||
reject(res);
|
reject(new SendMessageProtoError(res));
|
||||||
} else {
|
} else {
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}
|
}
|
||||||
|
|
19
ts/textsecure/Types.d.ts
vendored
19
ts/textsecure/Types.d.ts
vendored
|
@ -208,3 +208,22 @@ export type ProcessedSent = Omit<
|
||||||
export type ProcessedSyncMessage = Omit<Proto.ISyncMessage, 'sent'> & {
|
export type ProcessedSyncMessage = Omit<Proto.ISyncMessage, 'sent'> & {
|
||||||
sent?: ProcessedSent;
|
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>>;
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { isNumber } from 'lodash';
|
import { isNumber } from 'lodash';
|
||||||
import { CallbackResultType } from '../textsecure/SendMessage';
|
import { CallbackResultType } from '../textsecure/Types.d';
|
||||||
import dataInterface from '../sql/Client';
|
import dataInterface from '../sql/Client';
|
||||||
|
|
||||||
const { insertSentProto } = dataInterface;
|
const { insertSentProto } = dataInterface;
|
||||||
|
|
|
@ -22,13 +22,12 @@ import { isEnabled } from '../RemoteConfig';
|
||||||
|
|
||||||
import { isOlderThan } from './timestamp';
|
import { isOlderThan } from './timestamp';
|
||||||
import {
|
import {
|
||||||
CallbackResultType,
|
|
||||||
GroupSendOptionsType,
|
GroupSendOptionsType,
|
||||||
SendOptionsType,
|
SendOptionsType,
|
||||||
} from '../textsecure/SendMessage';
|
} from '../textsecure/SendMessage';
|
||||||
import { IdentityKeys, SenderKeys, Sessions } from '../LibSignalStores';
|
import { IdentityKeys, SenderKeys, Sessions } from '../LibSignalStores';
|
||||||
import { ConversationModel } from '../models/conversations';
|
import { ConversationModel } from '../models/conversations';
|
||||||
import { DeviceType } from '../textsecure/Types.d';
|
import { DeviceType, CallbackResultType } from '../textsecure/Types.d';
|
||||||
import { getKeysForIdentifier } from '../textsecure/getKeysForIdentifier';
|
import { getKeysForIdentifier } from '../textsecure/getKeysForIdentifier';
|
||||||
import { ConversationAttributesType } from '../model-types.d';
|
import { ConversationAttributesType } from '../model-types.d';
|
||||||
import {
|
import {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue