forked from saneki-discontinued/node-toxcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.js
252 lines (231 loc) · 6.8 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
* This file is part of node-toxcore.
*
* node-toxcore is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* node-toxcore is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with node-toxcore. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* @file errors.js - Provides functions for handling errors and error values.
* @todo Remove check* function, rename almost all
*/
var path = require('path');
var consts = require(path.join(__dirname, 'consts'));
var ToxError = require(path.join(__dirname, 'toxerror'));
module.exports = {
/**
* Check the error value that may have been set by tox_new, and throw
* the corresponding error (if any).
* @private
* @param {Number} val - Error value to check
* @todo Get an Error instead of throw
*/
checkToxNewError: function(val) {
if(val !== consts.TOX_ERR_NEW_OK) {
throw (new ToxError('TOX_ERR_NEW', val));
}
},
/**
* Get an Error from a TOX_ERR_BOOTSTRAP value. If none,
* will return undefined.
* @private
* @param {Number} val - TOX_ERR_BOOTSTRAP value
* @return {ToxError} Error, if any
*/
bootstrap: function(val) {
if(val !== consts.TOX_ERR_BOOTSTRAP_OK) {
return (new ToxError('TOX_ERR_BOOTSTRAP', val));
}
},
/**
* Get an Error from a TOX_ERR_FILE_CONTROL value.
* @private
*/
fileControl: function(val) {
if(val !== consts.TOX_ERR_FILE_CONTROL_OK) {
return (new ToxError('TOX_ERR_FILE_CONTROL', val));
}
},
/**
* Get an Error from a TOX_ERR_FILE_SEEK value.
* @private
*/
fileSeek: function(val) {
if(val !== consts.TOX_ERR_FILE_SEEK_OK) {
return (new ToxError('TOX_ERR_FILE_SEEK', val));
}
},
/**
* Get an Error from a TOX_ERR_FILE_GET value.
* @private
*/
fileGet: function(val) {
if(val !== consts.TOX_ERR_FILE_GET_OK) {
return (new ToxError('TOX_ERR_FILE_GET', val));
}
},
/**
* Get an Error from a TOX_ERR_FILE_SEND value.
* @private
*/
fileSend: function(val) {
if(val !== consts.TOX_ERR_FILE_SEND_OK) {
return (new ToxError('TOX_ERR_FILE_SEND', val));
}
},
/**
* Get an Error from a TOX_ERR_FILE_SEND_CHUNK value.
* @private
*/
fileSendChunk: function(val) {
if(val !== consts.TOX_ERR_FILE_SEND_CHUNK_OK) {
return (new ToxError('TOX_ERR_FILE_SEND_CHUNK', val));
}
},
/**
* Get an Error from a TOX_ERR_FRIEND_ADD value.
* If none, will return undefined.
* @private
* @param {Number} val - TOX_ERR_FRIEND_ADD value
* @return {ToxError} Error, if any
*/
friendAdd: function(val) {
if(val !== consts.TOX_ERR_FRIEND_ADD_OK) {
return (new ToxError('TOX_ERR_FRIEND_ADD', val));
}
},
/**
* Get an Error from a TOX_ERR_FRIEND_BY_PUBLIC_KEY value.
* If none, will return undefined.
* @private
* @param {Number} val - TOX_ERR_FRIEND_BY_PUBLIC_KEY value
* @return {ToxError} Error, if any
*/
friendByPublicKey: function(val) {
if(val !== consts.TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK) {
return (new ToxError('TOX_ERR_FRIEND_BY_PUBLIC_KEY', val));
}
},
/**
* Get an Error from a TOX_ERR_FRIEND_DELETE value.
* @private
*/
friendDelete: function(val) {
if(val !== consts.TOX_ERR_FRIEND_DELETE_OK) {
return (new ToxError('TOX_ERR_FRIEND_DELETE', val));
}
},
/**
* Get an Error from a TOX_ERR_FRIEND_GET_LAST_ONLINE
* value.
* @private
*/
friendGetLastOnline: function(val) {
if(val !== consts.TOX_ERR_FRIEND_GET_LAST_ONLINE_OK) {
return (new ToxError('TOX_ERR_FRIEND_GET_LAST_ONLINE', val));
}
},
/**
* Get an Error from a TOX_ERR_FRIEND_GET_PUBLIC_KEY value.
* If none, will return undefined.
* @private
* @param {Number} val - TOX_ERR_FRIEND_GET_PUBLIC_KEY value
* @return {ToxError} Error, if any
*/
friendGetPublicKey: function(val) {
if(val !== consts.TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK) {
return (new ToxError('TOX_ERR_FRIEND_GET_PUBLIC_KEY', val));
}
},
/**
* Get an Error from a TOX_ERR_FRIEND_CUSTOM_PACKET value.
* If none, will return undefined.
* @private
* @param {Number} val - TOX_ERR_FRIEND_CUSTOM_PACKET value
* @return {ToxError} Error, if any
*/
friendCustomPacket: function(val) {
if(val !== consts.TOX_ERR_FRIEND_CUSTOM_PACKET_OK) {
return (new ToxError('TOX_ERR_FRIEND_CUSTOM_PACKET', val));
}
},
/**
* Get an Error from a TOX_ERR_FRIEND_QUERY value.
* If none, will return undefined.
* @private
* @param {Number} val - TOX_ERR_FRIEND_QUERY value
* @return {ToxError} Error, if any
*/
friendQuery: function(val) {
if(val !== consts.TOX_ERR_FRIEND_QUERY_OK) {
return (new ToxError('TOX_ERR_FRIEND_QUERY', val));
}
},
/**
* Get an Error from a TOX_ERR_FRIEND_SEND_MESSAGE value.
* If none, will return undefined.
* @private
* @param {Number} val - TOX_ERR_FRIEND_SEND_MESSAGE value
* @return {ToxError} Error, if any
*/
friendSendMessage: function(val) {
if(val !== consts.TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
return (new ToxError('TOX_ERR_FRIEND_SEND_MESSAGE', val));
}
},
/**
* Get an Error from a TOX_ERR_GET_PORT value. If none,
* will return undefined.
* @private
* @param {Number} val - TOX_ERR_GET_PORT value
* @return {ToxError} Error, if any
*/
getPort: function(val) {
if(val !== consts.TOX_ERR_GET_PORT_OK) {
return (new ToxError('TOX_ERR_GET_PORT', val));
}
},
/**
* Get an Error from a TOX_ERR_SET_INFO value. If none,
* will return undefined.
* @private
* @param {Number} val - TOX_ERR_SET_INFO value
* @return {ToxError} Error, if any
*/
setInfo: function(val) {
if(val !== consts.TOX_ERR_SET_INFO_OK) {
return (new ToxError('TOX_ERR_SET_INFO', val));
}
},
/**
* Get an Error from a TOX_ERR_SET_TYPING value. If none,
* will return undefined.
* @private
* @param {Number} val - TOX_ERR_SET_TYPING value
* @return {ToxError} Error, if any
*/
setTyping: function(val) {
if(val !== consts.TOX_ERR_SET_TYPING_OK) {
return (new ToxError('TOX_ERR_SET_TYPING', val));
}
},
/**
* Get an error for when a function returns unsuccessful, but
* its error value indicates success.
* @private
* @return {ToxError} Error
*/
unsuccessful: function() {
return new ToxError('TOX_FUNC_RETURNED_UNSUCCESSFUL', 0, 'api function returned unsuccessful, but error value indicates success');
}
};