@como/como-client 0.9.3 → 0.9.4
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.
- package/lib/como.js +23 -16
- package/package.json +1 -1
- package/src/como.js +15 -7
package/lib/como.js
CHANGED
|
@@ -883,7 +883,7 @@ var Como = function () {
|
|
|
883
883
|
key: 'login',
|
|
884
884
|
value: function () {
|
|
885
885
|
var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(identifier, type, reCaptchaToken, recaptchaTokenType, devicePlatform, isWhatsapp) {
|
|
886
|
-
var api, data, _error$response$data8, code, message;
|
|
886
|
+
var api, data, _error$response$data8, code, message, retryAfter, loginError;
|
|
887
887
|
|
|
888
888
|
return _regenerator2.default.wrap(function _callee12$(_context12) {
|
|
889
889
|
while (1) {
|
|
@@ -903,17 +903,25 @@ var Como = function () {
|
|
|
903
903
|
_context12.t0 = _context12['catch'](1);
|
|
904
904
|
|
|
905
905
|
if (!(_context12.t0.response && _context12.t0.response.data)) {
|
|
906
|
-
_context12.next =
|
|
906
|
+
_context12.next = 15;
|
|
907
907
|
break;
|
|
908
908
|
}
|
|
909
909
|
|
|
910
|
-
_error$response$data8 = _context12.t0.response.data, code = _error$response$data8.code, message = _error$response$data8.message;
|
|
911
|
-
|
|
910
|
+
_error$response$data8 = _context12.t0.response.data, code = _error$response$data8.code, message = _error$response$data8.message, retryAfter = _error$response$data8.retryAfter;
|
|
911
|
+
loginError = new Error(code || message);
|
|
912
|
+
// When a request lands inside its OTP backoff the server states how long
|
|
913
|
+
// to wait. Only code and message used to survive this rethrow, which left
|
|
914
|
+
// the app inventing a countdown of its own.
|
|
912
915
|
|
|
913
|
-
|
|
916
|
+
if (typeof retryAfter === 'number') {
|
|
917
|
+
loginError.retryAfter = retryAfter;
|
|
918
|
+
}
|
|
919
|
+
throw loginError;
|
|
920
|
+
|
|
921
|
+
case 15:
|
|
914
922
|
throw _context12.t0;
|
|
915
923
|
|
|
916
|
-
case
|
|
924
|
+
case 16:
|
|
917
925
|
case 'end':
|
|
918
926
|
return _context12.stop();
|
|
919
927
|
}
|
|
@@ -942,7 +950,7 @@ var Como = function () {
|
|
|
942
950
|
key: 'loginVerify',
|
|
943
951
|
value: function () {
|
|
944
952
|
var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(identifier, type, code, reCaptchaToken, recaptchaTokenType, devicePlatform) {
|
|
945
|
-
var api, _ref14, consent, _error$response$data9, errCode, message;
|
|
953
|
+
var api, _ref14, consent, _error$response$data9, errCode, message, retryAfter, verifyError;
|
|
946
954
|
|
|
947
955
|
return _regenerator2.default.wrap(function _callee13$(_context13) {
|
|
948
956
|
while (1) {
|
|
@@ -970,17 +978,16 @@ var Como = function () {
|
|
|
970
978
|
break;
|
|
971
979
|
}
|
|
972
980
|
|
|
973
|
-
_error$response$data9 = _context13.t0.response.data, errCode = _error$response$data9.code, message = _error$response$data9.message;
|
|
981
|
+
_error$response$data9 = _context13.t0.response.data, errCode = _error$response$data9.code, message = _error$response$data9.message, retryAfter = _error$response$data9.retryAfter;
|
|
982
|
+
// The wrong-code case keeps reporting the message rather than the code,
|
|
983
|
+
// since callers match on that string.
|
|
974
984
|
|
|
975
|
-
|
|
976
|
-
_context13.next = 15;
|
|
977
|
-
break;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
throw new Error(message);
|
|
985
|
+
verifyError = message && message === 'Invalid verification Code' ? new Error(message) : new Error(errCode || message);
|
|
981
986
|
|
|
982
|
-
|
|
983
|
-
|
|
987
|
+
if (typeof retryAfter === 'number') {
|
|
988
|
+
verifyError.retryAfter = retryAfter;
|
|
989
|
+
}
|
|
990
|
+
throw verifyError;
|
|
984
991
|
|
|
985
992
|
case 16:
|
|
986
993
|
throw _context13.t0;
|
package/package.json
CHANGED
package/src/como.js
CHANGED
|
@@ -391,8 +391,13 @@ class Como {
|
|
|
391
391
|
return data;
|
|
392
392
|
} catch (error) {
|
|
393
393
|
if (error.response && error.response.data) {
|
|
394
|
-
const { code, message } = error.response.data;
|
|
395
|
-
|
|
394
|
+
const { code, message, retryAfter } = error.response.data;
|
|
395
|
+
const loginError = new Error(code || message);
|
|
396
|
+
// When a request lands inside its OTP backoff the server states how long
|
|
397
|
+
// to wait. Only code and message used to survive this rethrow, which left
|
|
398
|
+
// the app inventing a countdown of its own.
|
|
399
|
+
if (typeof retryAfter === 'number') { loginError.retryAfter = retryAfter; }
|
|
400
|
+
throw loginError;
|
|
396
401
|
}
|
|
397
402
|
throw error;
|
|
398
403
|
}
|
|
@@ -414,11 +419,14 @@ class Como {
|
|
|
414
419
|
this.comoData.consent = consent;
|
|
415
420
|
} catch (error) {
|
|
416
421
|
if (error.response && error.response.data) {
|
|
417
|
-
const { code: errCode, message } = error.response.data;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
+
const { code: errCode, message, retryAfter } = error.response.data;
|
|
423
|
+
// The wrong-code case keeps reporting the message rather than the code,
|
|
424
|
+
// since callers match on that string.
|
|
425
|
+
const verifyError = (message && message === 'Invalid verification Code')
|
|
426
|
+
? new Error(message)
|
|
427
|
+
: new Error(errCode || message);
|
|
428
|
+
if (typeof retryAfter === 'number') { verifyError.retryAfter = retryAfter; }
|
|
429
|
+
throw verifyError;
|
|
422
430
|
}
|
|
423
431
|
throw error;
|
|
424
432
|
}
|