2018-07-21 21:51:20 +00:00
|
|
|
/* global window */
|
2018-05-02 01:54:43 +00:00
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
// eslint-disable-next-line func-names
|
|
|
|
(function() {
|
2018-05-02 01:54:43 +00:00
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
|
|
|
|
function inherit(Parent, Child) {
|
2018-07-21 21:51:20 +00:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
2018-05-02 01:54:43 +00:00
|
|
|
Child.prototype = Object.create(Parent.prototype, {
|
|
|
|
constructor: {
|
|
|
|
value: Child,
|
|
|
|
writable: true,
|
|
|
|
configurable: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function appendStack(newError, originalError) {
|
2018-07-21 21:51:20 +00:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
newError.stack += `\nOriginal stack:\n${originalError.stack}`;
|
2018-05-02 01:54:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
function ReplayableError(options = {}) {
|
2018-05-02 01:54:43 +00:00
|
|
|
this.name = options.name || 'ReplayableError';
|
|
|
|
this.message = options.message;
|
|
|
|
|
|
|
|
Error.call(this, 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);
|
2018-01-08 19:08:25 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 01:54:43 +00:00
|
|
|
this.functionCode = options.functionCode;
|
|
|
|
}
|
|
|
|
inherit(Error, ReplayableError);
|
|
|
|
|
|
|
|
function IncomingIdentityKeyError(number, message, key) {
|
2018-07-21 21:51:20 +00:00
|
|
|
// eslint-disable-next-line prefer-destructuring
|
2018-05-02 01:54:43 +00:00
|
|
|
this.number = number.split('.')[0];
|
|
|
|
this.identityKey = key;
|
|
|
|
|
|
|
|
ReplayableError.call(this, {
|
|
|
|
name: 'IncomingIdentityKeyError',
|
2018-07-21 21:51:20 +00:00
|
|
|
message: `The identity of ${this.number} has changed.`,
|
2018-05-02 01:54:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
inherit(ReplayableError, IncomingIdentityKeyError);
|
|
|
|
|
|
|
|
function OutgoingIdentityKeyError(number, message, timestamp, identityKey) {
|
2018-07-21 21:51:20 +00:00
|
|
|
// eslint-disable-next-line prefer-destructuring
|
2018-05-02 01:54:43 +00:00
|
|
|
this.number = number.split('.')[0];
|
|
|
|
this.identityKey = identityKey;
|
|
|
|
|
|
|
|
ReplayableError.call(this, {
|
|
|
|
name: 'OutgoingIdentityKeyError',
|
2018-07-21 21:51:20 +00:00
|
|
|
message: `The identity of ${this.number} has changed.`,
|
2018-05-02 01:54:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
inherit(ReplayableError, OutgoingIdentityKeyError);
|
|
|
|
|
|
|
|
function OutgoingMessageError(number, message, timestamp, httpError) {
|
2018-07-27 01:13:56 +00:00
|
|
|
// eslint-disable-next-line prefer-destructuring
|
|
|
|
this.number = number.split('.')[0];
|
|
|
|
|
2018-05-02 01:54:43 +00:00
|
|
|
ReplayableError.call(this, {
|
|
|
|
name: 'OutgoingMessageError',
|
|
|
|
message: httpError ? httpError.message : 'no http error',
|
|
|
|
});
|
|
|
|
|
|
|
|
if (httpError) {
|
|
|
|
this.code = httpError.code;
|
|
|
|
appendStack(this, httpError);
|
2015-09-22 22:52:42 +00:00
|
|
|
}
|
2018-05-02 01:54:43 +00:00
|
|
|
}
|
|
|
|
inherit(ReplayableError, OutgoingMessageError);
|
|
|
|
|
2018-07-27 01:13:56 +00:00
|
|
|
function SendMessageNetworkError(number, jsonData, httpError) {
|
2018-05-02 01:54:43 +00:00
|
|
|
this.number = number;
|
|
|
|
this.code = httpError.code;
|
|
|
|
|
|
|
|
ReplayableError.call(this, {
|
|
|
|
name: 'SendMessageNetworkError',
|
|
|
|
message: httpError.message,
|
|
|
|
});
|
|
|
|
|
|
|
|
appendStack(this, httpError);
|
|
|
|
}
|
|
|
|
inherit(ReplayableError, SendMessageNetworkError);
|
|
|
|
|
2018-07-27 01:13:56 +00:00
|
|
|
function SignedPreKeyRotationError() {
|
2018-05-02 01:54:43 +00:00
|
|
|
ReplayableError.call(this, {
|
|
|
|
name: 'SignedPreKeyRotationError',
|
|
|
|
message: 'Too many signed prekey rotation failures',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
inherit(ReplayableError, SignedPreKeyRotationError);
|
|
|
|
|
|
|
|
function MessageError(message, httpError) {
|
|
|
|
this.code = httpError.code;
|
|
|
|
|
|
|
|
ReplayableError.call(this, {
|
|
|
|
name: 'MessageError',
|
|
|
|
message: httpError.message,
|
|
|
|
});
|
|
|
|
|
|
|
|
appendStack(this, httpError);
|
|
|
|
}
|
|
|
|
inherit(ReplayableError, MessageError);
|
|
|
|
|
|
|
|
function UnregisteredUserError(number, httpError) {
|
|
|
|
this.message = httpError.message;
|
|
|
|
this.name = 'UnregisteredUserError';
|
|
|
|
|
|
|
|
Error.call(this, this.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);
|
2017-02-16 02:27:06 +00:00
|
|
|
}
|
2014-12-19 01:50:04 +00:00
|
|
|
|
2018-05-02 01:54:43 +00:00
|
|
|
this.number = number;
|
|
|
|
this.code = httpError.code;
|
|
|
|
|
|
|
|
appendStack(this, httpError);
|
|
|
|
}
|
|
|
|
inherit(Error, UnregisteredUserError);
|
|
|
|
|
|
|
|
window.textsecure.UnregisteredUserError = UnregisteredUserError;
|
|
|
|
window.textsecure.SendMessageNetworkError = SendMessageNetworkError;
|
|
|
|
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
|
|
|
|
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;
|
|
|
|
window.textsecure.ReplayableError = ReplayableError;
|
|
|
|
window.textsecure.OutgoingMessageError = OutgoingMessageError;
|
|
|
|
window.textsecure.MessageError = MessageError;
|
|
|
|
window.textsecure.SignedPreKeyRotationError = SignedPreKeyRotationError;
|
2014-12-19 01:50:04 +00:00
|
|
|
})();
|