forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPubnubError.java
More file actions
509 lines (421 loc) · 16.2 KB
/
Copy pathPubnubError.java
File metadata and controls
509 lines (421 loc) · 16.2 KB
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
package com.pubnub.api;
import org.json.JSONObject;
/**
* PubnubError object is passed to errorCallback. It contains details of error, like
* error code, error string, and optional message
*
* @author Pubnub
*
*/
public class PubnubError {
// Error Codes
/**
* Timeout Error .
*/
public static final int PNERR_TIMEOUT = 100;
/**
*
*/
public static final int PNERR_PUBNUB_ERROR = 101;
/**
* Connect Exception .
* Network Unreachable.
*/
public static final int PNERR_CONNECT_EXCEPTION = 102;
/**
* Please check network connectivity.
* Please contact support with error details if issue persists.
*/
public static final int PNERR_HTTP_ERROR = 103;
/**
* Client Timeout .
*/
public static final int PNERR_CLIENT_TIMEOUT = 104;
/**
* An ULS singature error occurred .
* Please contact support with error details.
*/
static final int PNERR_ULSSIGN_ERROR = 105;
/**
* Please verify if network is reachable
*/
public static final int PNERR_NETWORK_ERROR = 106;
/**
* Pubnub Exception .
*/
public static final int PNERR_PUBNUB_EXCEPTION = 108;
/**
* Disconnect .
*/
public static final int PNERR_DISCONNECT = 109;
/**
* Disconnect and Resubscribe Received .
*/
public static final int PNERR_DISCONN_AND_RESUB = 110;
/**
* Gateway Timeout
*/
public static final int PNERR_GATEWAY_TIMEOUT = 111;
/**
* Pubnub server returned HTTP 403 forbidden status code.
* Happens when wrong authentication key is used .
*/
public static final int PNERR_FORBIDDEN = 112;
/**
* Pubnub server returned HTTP 401 unauthorized status code
* Happens when authentication key is missing .
*/
public static final int PNERR_UNAUTHORIZED = 113;
/**
* Secret key not configured
*/
public static final int PNERR_SECRET_KEY_MISSING = 114;
// internal error codes
/**
* Error while encrypting message to be published to Pubnub Cloud .
* Please contact support with error details.
*/
public static final int PNERR_ENCRYPTION_ERROR = 115;
/**
* Decryption Error .
* Please contact support with error details.
*/
public static final int PNERR_DECRYPTION_ERROR = 116;
/**
* Invalid Json .
* Please contact support with error details.
*/
public static final int PNERR_INVALID_JSON = 117;
/**
* Unable to open input stream .
* Please contact support with error details.
*/
static final int PNERR_GETINPUTSTREAM = 118;
/**
* Malformed URL .
* Please contact support with error details .
*/
static final int PNERR_MALFORMED_URL = 119;
/**
* Error in opening URL .
* Please contact support with error details.
*/
public static final int PNERR_URL_OPEN = 120;
/**
* JSON Error while processing API response.
* Please contact support with error details.
*/
static final int PNERR_JSON_ERROR = 121;
/**
* Protocol Exception .
* Please contact support with error details.
*/
static final int PNERR_PROTOCOL_EXCEPTION = 122;
/**
* Unable to read input stream .
* Please contact support with error details.
*/
static final int PNERR_READINPUT = 123;
/**
* Bad gateway .
* Please contact support with error details.
*/
static final int PNERR_BAD_GATEWAY = 124;
/**
* Pubnub server returned HTTP 502 internal server error status code.
* Please contact support with error details.
*/
static final int PNERR_INTERNAL_ERROR = 125;
/**
* Parsing Error .
*/
static final int PNERR_PARSING_ERROR = 126;
/**
* Bad Request .
* Please contact support with error details.
*/
static final int PNERR_BAD_REQUEST = 127;
public static final int PNERR_HTTP_RC_ERROR = 128;
/**
* Pubnub server or intermediate server returned HTTP 404 unauthorized status code
*
*/
public static final int PNERR_NOT_FOUND = 129;
/**
* Subscribe Timeout .
*/
static final int PNERR_HTTP_SUBSCRIBE_TIMEOUT = 130;
/**
* Invalid arguments provided to API
*
*/
public static final int PNERR_INVALID_ARGUMENTS = 131;
/**
* Channel missing
*
*/
public static final int PNERR_CHANNEL_MISSING = 132;
/**
* Pubnub connection not set on sender
*
*/
public static final int PNERR_CONNECTION_NOT_SET = 133;
/**
* Error while parsing group name
*/
public static final int PNERR_CHANNEL_GROUP_PARSING_ERROR = 134;
// Error Objects
static final PubnubError PNERROBJ_TIMEOUT =
new PubnubError (
PNERR_TIMEOUT, "Timeout Occurred"
);
static final PubnubError PNERROBJ_INTERNAL_ERROR =
new PubnubError (
PNERR_INTERNAL_ERROR , "Internal Error"
);
static final PubnubError PNERROBJ_ENCRYPTION_ERROR =
new PubnubError (
PNERR_ENCRYPTION_ERROR ,
"Error while encrypting message to be published to Pubnub Cloud ." +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_DECRYPTION_ERROR =
new PubnubError (
PNERR_DECRYPTION_ERROR ,
"Decryption Error. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_INVALID_JSON =
new PubnubError (
PNERR_INVALID_JSON ,
"Invalid Json. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_JSON_ERROR =
new PubnubError (
PNERR_JSON_ERROR ,
"JSON Error while processing API response. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_MALFORMED_URL =
new PubnubError (
PNERR_MALFORMED_URL ,
"Malformed URL ." +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_PUBNUB_ERROR =
new PubnubError (
PNERR_PUBNUB_ERROR ,
"Pubnub Error"
);
static final PubnubError PNERROBJ_URL_OPEN =
new PubnubError (
PNERR_URL_OPEN ,
"Error opening url. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_PROTOCOL_EXCEPTION =
new PubnubError (
PNERR_PROTOCOL_EXCEPTION ,
"Protocol Exception. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_CONNECT_EXCEPTION =
new PubnubError (
PNERR_CONNECT_EXCEPTION ,
"Connect Exception. " +
"Please verify if network is reachable. "
);
static final PubnubError PNERROBJ_HTTP_RC_ERROR =
new PubnubError (
PNERR_HTTP_RC_ERROR ,
"Unable to get Response Code. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_GETINPUTSTREAM =
new PubnubError (
PNERR_GETINPUTSTREAM ,
"Unable to get Input Stream. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_READINPUT =
new PubnubError (
PNERR_READINPUT ,
"Unable to read Input Stream. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_BAD_REQUEST =
new PubnubError (
PNERR_BAD_REQUEST ,
"Bad request. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_HTTP_ERROR =
new PubnubError (
PNERR_HTTP_ERROR ,
"HTTP Error. " +
"Please check network connectivity. " +
"Please contact support with error details if issue persists."
);
static final PubnubError PNERROBJ_BAD_GATEWAY =
new PubnubError (
PNERR_BAD_GATEWAY ,
"Bad Gateway. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_CLIENT_TIMEOUT =
new PubnubError (
PNERR_CLIENT_TIMEOUT ,
"Client Timeout"
);
static final PubnubError PNERROBJ_GATEWAY_TIMEOUT =
new PubnubError (
PNERR_GATEWAY_TIMEOUT ,
"Gateway Timeout"
);
static final PubnubError PNERROBJ_5023_INTERNAL_ERROR =
new PubnubError (
PNERR_INTERNAL_ERROR ,
"Internal Server Error. " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_PARSING_ERROR =
new PubnubError (
PNERR_PARSING_ERROR ,
"Parsing Error"
);
static final PubnubError PNERROBJ_PUBNUB_EXCEPTION =
new PubnubError (
PNERR_PUBNUB_EXCEPTION ,
"Pubnub Exception"
);
static final PubnubError PNERROBJ_DISCONNECT =
new PubnubError (
PNERR_DISCONNECT ,
"Disconnect"
);
static final PubnubError PNERROBJ_DISCONN_AND_RESUB =
new PubnubError (
PNERR_DISCONN_AND_RESUB ,
"Disconnect and Resubscribe"
);
static final PubnubError PNERROBJ_FORBIDDEN =
new PubnubError (
PNERR_FORBIDDEN ,
"Authentication Failure. " +
"Incorrect Authentication Key"
);
static final PubnubError PNERROBJ_UNAUTHORIZED =
new PubnubError (
PNERR_UNAUTHORIZED ,
"Authentication Failure. " +
"Authentication Key is missing"
);
static final PubnubError PNERROBJ_SECRET_KEY_MISSING =
new PubnubError (
PNERR_SECRET_KEY_MISSING ,
"ULS configuration failed. Secret Key not configured. "
);
static final PubnubError PNERROBJ_ULSSIGN_ERROR =
new PubnubError (
PNERR_ULSSIGN_ERROR ,
"Invalid Signature . " +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_5075_NETWORK_ERROR =
new PubnubError (
PNERR_NETWORK_ERROR ,
"Network Error. " +
"Please verify if network is reachable."
);
static final PubnubError PNERROBJ_NOT_FOUND_ERROR =
new PubnubError (
PNERR_NOT_FOUND ,
"Page Not Found" +
"Please verify if network is reachable." +
"Please contact support with error details."
);
static final PubnubError PNERROBJ_SUBSCRIBE_TIMEOUT =
new PubnubError (
PNERR_HTTP_SUBSCRIBE_TIMEOUT ,
"Subscribe Timeout."
);
static final PubnubError PNERROBJ_INVALID_ARGUMENTS =
new PubnubError (
PNERR_INVALID_ARGUMENTS ,
"INVALID ARGUMENTS."
);
static final PubnubError PNERROBJ_CHANNEL_MISSING =
new PubnubError (
PNERR_CHANNEL_MISSING ,
"Channel Missing."
);
static final PubnubError PNERROBJ_CONNECTION_NOT_SET =
new PubnubError (
PNERR_CONNECTION_NOT_SET ,
"Pubnub Connection not set"
);
static final PubnubError PNERROBJ_CHANNEL_GROUP_PARSING_ERROR =
new PubnubError (
PNERR_CHANNEL_GROUP_PARSING_ERROR ,
"Channel group name is invalid"
);
public final int errorCode;
public final int errorCodeExtended;
public final JSONObject errorObject;
private final String errorString;
private String message;
private PubnubError(int errorCode, int errorCodeExtended, String errorString, JSONObject errorObject, String message) {
this.errorCodeExtended = errorCodeExtended;
this.errorCode = errorCode;
this.errorString = errorString;
this.errorObject = errorObject;
this.message = message;
}
private PubnubError(int errorCode, int errorCodeExtended, String errorString) {
this(errorCode, errorCodeExtended, errorString, null, null);
}
private PubnubError(int errorCode, int errorCodeExtended, String errorString, JSONObject errorObject) {
this(errorCode, errorCodeExtended, errorString, errorObject, null);
}
private PubnubError(int errorCode, String errorString) {
this(errorCode, 0, errorString, null, null);
}
private PubnubError(int errorCode, int errorCodeExtended, String errorString, String message) {
this(errorCode, errorCodeExtended, errorString, null, message);
}
public PubnubError(PubnubError error, String message) {
this(error.errorCode, error.errorCodeExtended, error.errorString, null, message);
}
public PubnubError(PubnubError error, JSONObject errorObject) {
this(error.errorCode, error.errorCodeExtended, error.errorString, errorObject, null);
}
public String toString() {
String value = "[Error: " + errorCode + "-" + errorCodeExtended + "] : " + errorString;
if (errorObject != null) {
value += " : " + errorObject;
}
if (message != null && message.length() > 0) {
value += " : " + message;
}
return value;
}
static PubnubError getErrorObject(PubnubError error, String message) {
return new PubnubError(error.errorCode, error.errorCodeExtended, error.errorString, message);
}
static PubnubError getErrorObject(PubnubError error, String message, JSONObject errorObject) {
return new PubnubError(error.errorCode, error.errorCodeExtended, error.errorString, errorObject, message);
}
static PubnubError getErrorObject(PubnubError error, int errorCodeExtended, JSONObject errorObject) {
return new PubnubError(error.errorCode, errorCodeExtended, error.errorString, errorObject);
}
static PubnubError getErrorObject(PubnubError error, int errorCodeExtended) {
return new PubnubError(error.errorCode, errorCodeExtended, error.errorString);
}
static PubnubError getErrorObject(PubnubError error, int errorCodeExtended, String message) {
return new PubnubError(error.errorCode, errorCodeExtended, error.errorString, message);
}
public String getErrorString() {
return errorString;
}
}