Skip to content

Commit cbd7f9a

Browse files
authored
Use promiseRetry to retry gapi load (#1664)
We've been seeing a lot of errors (both user reports and automated error monitoring) in which the `gapi` script fails to load. Previously we were using `loadjs`'s built-in retry logic, but this does not do exponential backoff so will not behave well in a brief network outage. Instead just use `promiseRetry` like we do everywhere else.
1 parent 87380dd commit cbd7f9a

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/services/gapi.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import loadjs from 'loadjs';
22
import once from 'lodash-es/once';
3+
import promiseRetry from 'promise-retry';
34

45
import config from '../config';
56
import ExtendableError from '../util/ExtendableError';
@@ -16,17 +17,30 @@ class LoadError extends ExtendableError {}
1617

1718
let isGapiLoadedAndConfigured = false;
1819

19-
const loadGapi = once(async() => new Promise((resolve, reject) => {
20-
loadjs('https://apis.google.com/js/client.js', {
21-
success() {
22-
resolve(window.gapi);
23-
},
24-
error(failedPaths) {
25-
reject(new LoadError(`Failed to load ${failedPaths.join(', ')}`));
26-
},
27-
numRetries: 16,
28-
});
29-
}));
20+
const loadGapi = once(() => promiseRetry(
21+
async(retry) => {
22+
try {
23+
return await new Promise((resolve, reject) => {
24+
loadjs('https://apis.google.com/js/client.js', {
25+
success() {
26+
resolve(window.gapi);
27+
},
28+
error(failedPaths) {
29+
reject(new LoadError(`Failed to load ${failedPaths.join(', ')}`));
30+
},
31+
});
32+
});
33+
} catch (e) {
34+
return retry(e);
35+
}
36+
},
37+
{
38+
retries: 16,
39+
factor: 2,
40+
minTimeout: 200,
41+
maxTimeout: 4000,
42+
},
43+
));
3044

3145
export const loadAndConfigureGapi = once(async() => {
3246
const gapi = await loadGapi();

0 commit comments

Comments
 (0)