@webex/calling 3.12.0-mobius-socket.11 → 3.12.0-mobius-socket.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -281,111 +281,151 @@ function handleRegistrationErrors(_x, _x2, _x3, _x4, _x5) {
281
281
  */
282
282
  function _handleRegistrationErrors() {
283
283
  _handleRegistrationErrors = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(err, emitterCb, loggerContext, retry429Cb, restoreRegCb) {
284
- var lineError, errorCode, finalError, caller, retryAfter, errorBody, code, errorMessage, _caller, _errorMessage, _errorMessage2, _errorMessage3, _t, _t2;
284
+ var serverCount,
285
+ shouldDisconnect,
286
+ lineError,
287
+ errorCode,
288
+ finalError,
289
+ caller,
290
+ retryAfter,
291
+ errorBody,
292
+ code,
293
+ errorMessage,
294
+ _caller,
295
+ _errorMessage,
296
+ _errorMessage2,
297
+ _errorMessage3,
298
+ _args = arguments,
299
+ _t,
300
+ _t2;
285
301
  return _regenerator.default.wrap(function (_context) {
286
302
  while (1) switch (_context.prev = _context.next) {
287
303
  case 0:
304
+ serverCount = _args.length > 5 && _args[5] !== undefined ? _args[5] : 1;
305
+ shouldDisconnect = false;
288
306
  lineError = (0, _LineError.createLineError)('', {}, _types2.ERROR_TYPE.DEFAULT, _types3.RegistrationStatus.INACTIVE);
289
307
  errorCode = Number(err.statusCode);
290
308
  finalError = false;
291
309
  _Logger.default.warn("Status code: -> ".concat(errorCode), loggerContext);
292
310
  _t = errorCode;
293
- _context.next = _t === _types2.ERROR_CODE.BAD_REQUEST ? 1 : _t === _types2.ERROR_CODE.UNAUTHORIZED ? 2 : _t === _types2.ERROR_CODE.DEVICE_NOT_FOUND ? 3 : _t === _types2.ERROR_CODE.TOO_MANY_REQUESTS ? 4 : _t === _types2.ERROR_CODE.INTERNAL_SERVER_ERROR ? 5 : _t === _types2.ERROR_CODE.SERVICE_UNAVAILABLE ? 6 : _t === _types2.ERROR_CODE.FORBIDDEN ? 7 : 15;
311
+ _context.next = _t === _types2.ERROR_CODE.BAD_REQUEST ? 1 : _t === _types2.ERROR_CODE.UNAUTHORIZED ? 2 : _t === _types2.ERROR_CODE.DEVICE_NOT_FOUND ? 3 : _t === _types2.ERROR_CODE.TOO_MANY_REQUESTS ? 4 : _t === _types2.ERROR_CODE.INTERNAL_SERVER_ERROR ? 6 : _t === _types2.ERROR_CODE.SERVICE_UNAVAILABLE ? 7 : _t === _types2.ERROR_CODE.FORBIDDEN ? 8 : 16;
294
312
  break;
295
313
  case 1:
296
314
  finalError = true;
297
315
  _Logger.default.warn("400 Bad Request", loggerContext);
298
316
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.BAD_REQUEST, 'Invalid input. Please verify the required parameters, sign out and then sign back in with the valid data', _types3.RegistrationStatus.INACTIVE, lineError);
299
317
  emitterCb(lineError, finalError);
300
- return _context.abrupt("continue", 16);
318
+ shouldDisconnect = serverCount > 1;
319
+ return _context.abrupt("continue", 17);
301
320
  case 2:
302
321
  // Return it to the Caller
303
322
  finalError = true;
304
323
  _Logger.default.warn("401 Unauthorized", loggerContext);
305
324
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.TOKEN_ERROR, 'User is unauthorized due to an expired token. Sign out, then sign back in.', _types3.RegistrationStatus.INACTIVE, lineError);
306
325
  emitterCb(lineError, finalError);
307
- return _context.abrupt("continue", 16);
326
+ shouldDisconnect = serverCount > 1;
327
+ return _context.abrupt("continue", 17);
308
328
  case 3:
309
329
  finalError = true;
310
330
  _Logger.default.warn("404 Device Not Found", loggerContext);
311
331
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.NOT_FOUND, 'Webex Calling is unable to find your device. Sign out, then sign back in', _types3.RegistrationStatus.INACTIVE, lineError);
312
332
  emitterCb(lineError, finalError);
313
- return _context.abrupt("continue", 16);
333
+ shouldDisconnect = serverCount > 1;
334
+ return _context.abrupt("continue", 17);
314
335
  case 4:
315
336
  _Logger.default.warn("429 Too Many Requests", loggerContext);
316
337
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.TOO_MANY_REQUESTS, 'Server is handling too many request at the time. Wait a moment and try again', _types3.RegistrationStatus.INACTIVE, lineError);
317
338
  caller = loggerContext.method || 'handleErrors';
318
- if (retry429Cb && err.headers) {
319
- retryAfter = Number(err.headers['retry-after']);
320
- retry429Cb(retryAfter, caller);
339
+ if (!(retry429Cb && err.headers)) {
340
+ _context.next = 5;
341
+ break;
321
342
  }
322
- return _context.abrupt("continue", 16);
343
+ retryAfter = Number(err.headers['retry-after']);
344
+ _context.next = 5;
345
+ return retry429Cb(retryAfter, caller);
323
346
  case 5:
347
+ shouldDisconnect = false;
348
+ return _context.abrupt("continue", 17);
349
+ case 6:
324
350
  _Logger.default.warn("500 Internal Server Error", loggerContext);
325
351
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.SERVER_ERROR, 'An unknown error occurred while placing the request. Wait a moment and try again.', _types3.RegistrationStatus.INACTIVE, lineError);
326
352
  emitterCb(lineError, finalError);
327
- return _context.abrupt("continue", 16);
328
- case 6:
353
+ shouldDisconnect = serverCount > 1;
354
+ return _context.abrupt("continue", 17);
355
+ case 7:
329
356
  _Logger.default.warn("503 Service Unavailable", loggerContext);
330
357
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.SERVICE_UNAVAILABLE, 'An error occurred on the server while processing the request. Wait a moment and try again.', _types3.RegistrationStatus.INACTIVE, lineError);
331
358
  emitterCb(lineError, finalError);
332
- return _context.abrupt("continue", 16);
333
- case 7:
359
+ shouldDisconnect = serverCount > 1;
360
+ return _context.abrupt("continue", 17);
361
+ case 8:
334
362
  _Logger.default.warn("403 Forbidden", loggerContext);
335
363
  errorBody = err.body;
336
364
  if (errorBody) {
337
- _context.next = 8;
365
+ _context.next = 9;
338
366
  break;
339
367
  }
340
368
  _Logger.default.warn('Error response has no body, throwing default error', loggerContext);
341
369
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.FORBIDDEN_ERROR, 'An unauthorized action has been received. This action has been blocked. Please contact the administrator if this persists.', _types3.RegistrationStatus.INACTIVE, lineError);
342
370
  emitterCb(lineError, finalError);
343
- return _context.abrupt("return", finalError);
344
- case 8:
371
+ shouldDisconnect = serverCount > 1;
372
+ return _context.abrupt("return", {
373
+ finalError: finalError,
374
+ shouldDisconnect: shouldDisconnect
375
+ });
376
+ case 9:
345
377
  code = Number(errorBody.errorCode);
346
378
  _Logger.default.warn("Error code found : ".concat(code), loggerContext);
347
379
  _t2 = code;
348
- _context.next = _t2 === _types2.DEVICE_ERROR_CODE.DEVICE_LIMIT_EXCEEDED ? 9 : _t2 === _types2.DEVICE_ERROR_CODE.DEVICE_CREATION_DISABLED ? 11 : _t2 === _types2.DEVICE_ERROR_CODE.DEVICE_CREATION_FAILED ? 12 : 13;
380
+ _context.next = _t2 === _types2.DEVICE_ERROR_CODE.DEVICE_LIMIT_EXCEEDED ? 10 : _t2 === _types2.DEVICE_ERROR_CODE.DEVICE_CREATION_DISABLED ? 12 : _t2 === _types2.DEVICE_ERROR_CODE.DEVICE_CREATION_FAILED ? 13 : 14;
349
381
  break;
350
- case 9:
382
+ case 10:
351
383
  errorMessage = 'User device limit exceeded';
352
384
  _Logger.default.warn(errorMessage, loggerContext);
353
385
  if (!restoreRegCb) {
354
- _context.next = 10;
386
+ _context.next = 11;
355
387
  break;
356
388
  }
357
389
  _caller = loggerContext.method || 'handleErrors';
358
- _context.next = 10;
390
+ _context.next = 11;
359
391
  return restoreRegCb(errorBody, _caller);
360
- case 10:
361
- return _context.abrupt("continue", 14);
362
392
  case 11:
393
+ shouldDisconnect = false;
394
+ return _context.abrupt("continue", 15);
395
+ case 12:
363
396
  _errorMessage = 'User is not configured for WebRTC calling. Please contact the administrator to resolve this issue.';
364
397
  finalError = true;
365
398
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.FORBIDDEN_ERROR, _errorMessage, _types3.RegistrationStatus.INACTIVE, lineError);
366
399
  _Logger.default.warn(_errorMessage, loggerContext);
367
400
  emitterCb(lineError, true);
368
- return _context.abrupt("continue", 14);
369
- case 12:
401
+ shouldDisconnect = true;
402
+ return _context.abrupt("continue", 15);
403
+ case 13:
370
404
  _errorMessage2 = 'An unknown error occurred while provisioning the device. Wait a moment and try again.';
371
405
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.FORBIDDEN_ERROR, _errorMessage2, _types3.RegistrationStatus.INACTIVE, lineError);
372
406
  _Logger.default.warn(_errorMessage2, loggerContext);
373
407
  emitterCb(lineError, finalError);
374
- return _context.abrupt("continue", 14);
375
- case 13:
408
+ shouldDisconnect = serverCount > 1;
409
+ return _context.abrupt("continue", 15);
410
+ case 14:
376
411
  _errorMessage3 = 'An unknown error occurred. Wait a moment and try again. Please contact the administrator if the problem persists.';
377
412
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.FORBIDDEN_ERROR, _errorMessage3, _types3.RegistrationStatus.INACTIVE, lineError);
378
413
  _Logger.default.warn(_errorMessage3, loggerContext);
379
414
  emitterCb(lineError, finalError);
380
- case 14:
381
- return _context.abrupt("continue", 16);
415
+ shouldDisconnect = serverCount > 1;
382
416
  case 15:
417
+ return _context.abrupt("continue", 17);
418
+ case 16:
383
419
  updateLineErrorContext(loggerContext, _types2.ERROR_TYPE.DEFAULT, 'Unknown error', _types3.RegistrationStatus.INACTIVE, lineError);
384
420
  _Logger.default.warn("Unknown Error", loggerContext);
385
421
  emitterCb(lineError, finalError);
386
- case 16:
387
- return _context.abrupt("return", finalError);
422
+ shouldDisconnect = serverCount > 1;
388
423
  case 17:
424
+ return _context.abrupt("return", {
425
+ finalError: finalError,
426
+ shouldDisconnect: shouldDisconnect
427
+ });
428
+ case 18:
389
429
  case "end":
390
430
  return _context.stop();
391
431
  }