diff --git a/lib/api/helpers/withApiHandlers.js b/lib/api/helpers/withApiHandlers.js index 93de3e0e..a03542df 100644 --- a/lib/api/helpers/withApiHandlers.js +++ b/lib/api/helpers/withApiHandlers.js @@ -73,10 +73,16 @@ export default ({ call, hasSession, onUnlock, onError, onVerification }) => { const { status, name } = e; if (name === 'OfflineError') { + if (attempts > OFFLINE_RETRY_ATTEMPTS_MAX) { + throw e; + } return wait(OFFLINE_RETRY_DELAY).then(() => refresh(attempts + 1, OFFLINE_RETRY_ATTEMPTS_MAX)); } if (name === 'TimeoutError') { + if (attempts > OFFLINE_RETRY_ATTEMPTS_MAX) { + throw e; + } return refresh(attempts + 1, OFFLINE_RETRY_ATTEMPTS_MAX); } @@ -111,10 +117,16 @@ export default ({ call, hasSession, onUnlock, onError, onVerification }) => { const { status, name } = e; if (name === 'OfflineError') { + if (attempts > OFFLINE_RETRY_ATTEMPTS_MAX) { + return onError(e); + } return wait(OFFLINE_RETRY_DELAY).then(() => perform(attempts + 1, OFFLINE_RETRY_ATTEMPTS_MAX)); } if (name === 'TimeoutError') { + if (attempts > OFFLINE_RETRY_ATTEMPTS_MAX) { + return onError(e); + } return perform(attempts + 1, OFFLINE_RETRY_ATTEMPTS_MAX); } diff --git a/lib/api/tests.js b/lib/api/tests.js new file mode 100644 index 00000000..9a54e51f --- /dev/null +++ b/lib/api/tests.js @@ -0,0 +1,4 @@ +export const ping = () => ({ + url: 'tests/ping', + method: 'get' +}); diff --git a/lib/constants.ts b/lib/constants.ts index 20d71bca..66db893f 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -1,7 +1,7 @@ export const RETRY_DELAY_MAX = 10; // seconds export const RETRY_ATTEMPTS_MAX = 5; // how many times to try the same request export const OFFLINE_RETRY_DELAY = 2000; // how much time in ms to wait before retrying an offline request -export const OFFLINE_RETRY_ATTEMPTS_MAX = 3; // how many times to try the same request when offline +export const OFFLINE_RETRY_ATTEMPTS_MAX = 0; // how many times to try the same request when offline export const MILLISECOND = 1; export const SECOND = 1000; export const MINUTE = 60 * SECOND;