forked from signalapp/Signal-Desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.js
112 lines (100 loc) · 4 KB
/
errors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* vim: ts=4:sw=4:expandtab
*/
;(function() {
'use strict';
var registeredFunctions = {};
var Type = {
ENCRYPT_MESSAGE: 1,
INIT_SESSION: 2,
TRANSMIT_MESSAGE: 3,
REBUILD_MESSAGE: 4,
};
window.textsecure = window.textsecure || {};
window.textsecure.replay = {
Type: Type,
registerFunction: function(func, functionCode) {
registeredFunctions[functionCode] = func;
}
};
function ReplayableError(options) {
options = options || {};
this.name = options.name || 'ReplayableError';
this.functionCode = options.functionCode;
this.args = options.args;
}
ReplayableError.prototype = new Error();
ReplayableError.prototype.constructor = ReplayableError;
ReplayableError.prototype.replay = function() {
return registeredFunctions[this.functionCode].apply(window, this.args);
};
function IncomingIdentityKeyError(number, message, key) {
ReplayableError.call(this, {
functionCode : Type.INIT_SESSION,
args : [number, message]
});
this.number = number.split('.')[0];
this.name = 'IncomingIdentityKeyError';
this.message = "The identity of " + this.number + " has changed.";
this.identityKey = key;
}
IncomingIdentityKeyError.prototype = new ReplayableError();
IncomingIdentityKeyError.prototype.constructor = IncomingIdentityKeyError;
function OutgoingIdentityKeyError(number, message, timestamp, identityKey) {
ReplayableError.call(this, {
functionCode : Type.ENCRYPT_MESSAGE,
args : [number, message, timestamp]
});
this.number = number.split('.')[0];
this.name = 'OutgoingIdentityKeyError';
this.message = "The identity of " + this.number + " has changed.";
this.identityKey = identityKey;
}
OutgoingIdentityKeyError.prototype = new ReplayableError();
OutgoingIdentityKeyError.prototype.constructor = OutgoingIdentityKeyError;
function OutgoingMessageError(number, message, timestamp, httpError) {
ReplayableError.call(this, {
functionCode : Type.ENCRYPT_MESSAGE,
args : [number, message, timestamp]
});
this.name = 'OutgoingMessageError';
if (httpError) {
this.code = httpError.code;
this.message = httpError.message;
this.stack = httpError.stack;
}
}
OutgoingMessageError.prototype = new ReplayableError();
OutgoingMessageError.prototype.constructor = OutgoingMessageError;
function SendMessageNetworkError(number, jsonData, httpError, timestamp) {
ReplayableError.call(this, {
functionCode : Type.TRANSMIT_MESSAGE,
args : [number, jsonData, timestamp]
});
this.name = 'SendMessageNetworkError';
this.number = number;
this.code = httpError.code;
this.message = httpError.message;
this.stack = httpError.stack;
}
SendMessageNetworkError.prototype = new ReplayableError();
SendMessageNetworkError.prototype.constructor = SendMessageNetworkError;
function MessageError(message, httpError) {
ReplayableError.call(this, {
functionCode : Type.REBUILD_MESSAGE,
args : [message]
});
this.name = 'MessageError';
this.code = httpError.code;
this.message = httpError.message;
this.stack = httpError.stack;
}
MessageError.prototype = new ReplayableError();
MessageError.prototype.constructor = MessageError;
window.textsecure.SendMessageNetworkError = SendMessageNetworkError;
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;
window.textsecure.ReplayableError = ReplayableError;
window.textsecure.OutgoingMessageError = OutgoingMessageError;
window.textsecure.MessageError = MessageError;
})();