b7d56def82
* Starting to work through lint errors * libsignal-protocol: Update changes for primary repo compatibility * Step 1: task_with_timeout rename * Step 2: Apply the changes to TaskWithTimeout.ts * Step 1: All to-be-converted libtextsecure/*.js files moved * Step 2: No Typescript errors! * Get libtextsecure tests passing again * TSLint errors down to 1 * Compilation succeeds, no lint errors or test failures * WebSocketResources - update import for case-sensitive filesystems * Fixes for lint-deps * Remove unnecessary @ts-ignore * Fix inability to message your own contact after link * Add log message for the end of migration 20 * lint fix
164 lines
3.9 KiB
TypeScript
164 lines
3.9 KiB
TypeScript
// tslint:disable max-classes-per-file
|
|
|
|
function appendStack(newError: Error, originalError: Error) {
|
|
// eslint-disable-next-line no-param-reassign
|
|
newError.stack += `\nOriginal stack:\n${originalError.stack}`;
|
|
}
|
|
|
|
export class ReplayableError extends Error {
|
|
name: string;
|
|
message: string;
|
|
functionCode?: number;
|
|
|
|
constructor(options: {
|
|
name?: string;
|
|
message: string;
|
|
functionCode?: number;
|
|
}) {
|
|
super(options.message);
|
|
|
|
this.name = options.name || 'ReplayableError';
|
|
this.message = options.message;
|
|
|
|
// Maintains proper stack trace, where our error was thrown (only available on V8)
|
|
// via https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this);
|
|
}
|
|
|
|
this.functionCode = options.functionCode;
|
|
}
|
|
}
|
|
|
|
export class IncomingIdentityKeyError extends ReplayableError {
|
|
identifier: string;
|
|
identityKey: ArrayBuffer;
|
|
|
|
// Note: Data to resend message is no longer captured
|
|
constructor(incomingIdentifier: string, _m: ArrayBuffer, key: ArrayBuffer) {
|
|
const identifer = incomingIdentifier.split('.')[0];
|
|
|
|
super({
|
|
name: 'IncomingIdentityKeyError',
|
|
message: `The identity of ${identifer} has changed.`,
|
|
});
|
|
|
|
this.identifier = identifer;
|
|
this.identityKey = key;
|
|
}
|
|
}
|
|
|
|
export class OutgoingIdentityKeyError extends ReplayableError {
|
|
identifier: string;
|
|
identityKey: ArrayBuffer;
|
|
|
|
// Note: Data to resend message is no longer captured
|
|
constructor(
|
|
incomingIdentifier: string,
|
|
_m: ArrayBuffer,
|
|
_t: number,
|
|
identityKey: ArrayBuffer
|
|
) {
|
|
const identifier = incomingIdentifier.split('.')[0];
|
|
|
|
super({
|
|
name: 'OutgoingIdentityKeyError',
|
|
message: `The identity of ${identifier} has changed.`,
|
|
});
|
|
|
|
this.identifier = identifier;
|
|
this.identityKey = identityKey;
|
|
}
|
|
}
|
|
|
|
export class OutgoingMessageError extends ReplayableError {
|
|
identifier: string;
|
|
code?: any;
|
|
|
|
// Note: Data to resend message is no longer captured
|
|
constructor(
|
|
incomingIdentifier: string,
|
|
_m: ArrayBuffer,
|
|
_t: number,
|
|
httpError?: Error
|
|
) {
|
|
const identifier = incomingIdentifier.split('.')[0];
|
|
|
|
super({
|
|
name: 'OutgoingMessageError',
|
|
message: httpError ? httpError.message : 'no http error',
|
|
});
|
|
|
|
this.identifier = identifier;
|
|
|
|
if (httpError) {
|
|
this.code = httpError.code;
|
|
appendStack(this, httpError);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class SendMessageNetworkError extends ReplayableError {
|
|
identifier: string;
|
|
|
|
constructor(identifier: string, _m: any, httpError: Error) {
|
|
super({
|
|
name: 'SendMessageNetworkError',
|
|
message: httpError.message,
|
|
});
|
|
|
|
this.identifier = identifier.split('.')[0];
|
|
this.code = httpError.code;
|
|
|
|
appendStack(this, httpError);
|
|
}
|
|
}
|
|
|
|
export class SignedPreKeyRotationError extends ReplayableError {
|
|
constructor() {
|
|
super({
|
|
name: 'SignedPreKeyRotationError',
|
|
message: 'Too many signed prekey rotation failures',
|
|
});
|
|
}
|
|
}
|
|
|
|
export class MessageError extends ReplayableError {
|
|
code?: any;
|
|
|
|
constructor(_m: any, httpError: Error) {
|
|
super({
|
|
name: 'MessageError',
|
|
message: httpError.message,
|
|
});
|
|
|
|
this.code = httpError.code;
|
|
|
|
appendStack(this, httpError);
|
|
}
|
|
}
|
|
|
|
export class UnregisteredUserError extends Error {
|
|
identifier: string;
|
|
code?: any;
|
|
|
|
constructor(identifier: string, httpError: Error) {
|
|
const message = httpError.message;
|
|
|
|
super(message);
|
|
|
|
this.message = message;
|
|
this.name = 'UnregisteredUserError';
|
|
|
|
// Maintains proper stack trace, where our error was thrown (only available on V8)
|
|
// via https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this);
|
|
}
|
|
|
|
this.identifier = identifier;
|
|
this.code = httpError.code;
|
|
|
|
appendStack(this, httpError);
|
|
}
|
|
}
|