Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/api/helpers/withApiHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/api/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const ping = () => ({
url: 'tests/ping',
method: 'get'
});
2 changes: 1 addition & 1 deletion lib/constants.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down