Skip to content

Commit d58118f

Browse files
committedOct 21, 2022
CR-13431 add CF_API_RETRIES
1 parent 8284feb commit d58118f

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"recursive-readdir-sync": "^1.0.6",
3838
"request": "^2.88.0",
3939
"request-promise": "^4.2.2",
40+
"retry-request" : "5.0.2",
4041
"rimraf": "^2.7.1"
4142
},
4243
"devDependencies": {

‎src/api/index.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
const _ = require('lodash');
12
const rp = require('request-promise');
3+
const Promise = require('bluebird');
4+
const retryRequest = require('retry-request');
25

36
class CodefreshAPI {
47

58
static async sendRequest(config, opts) {
69
if (config.env.retriesForCodefreshAPI) {
7-
let error;
8-
for (let i = 0; i < config.env.retriesForCodefreshAPI; i += 1) {
9-
try {
10-
// eslint-disable-next-line no-await-in-loop
11-
const result = await rp(opts);
12-
return result;
13-
} catch (e) {
14-
error = e;
15-
}
10+
opts.retries = config.env.retriesForCodefreshAPI;
11+
const response = await Promise.fromCallback(cb => retryRequest(opts, cb));
12+
const body = _.get(response, 'body');
13+
if (response.statusCode !== 200) {
14+
throw new Error(body);
1615
}
17-
throw error;
16+
return body;
1817
}
1918
return rp(opts);
2019
}

‎yarn.lock

+8
Original file line numberDiff line numberDiff line change
@@ -4152,6 +4152,14 @@ restore-cursor@^1.0.1:
41524152
exit-hook "^1.0.0"
41534153
onetime "^1.0.0"
41544154

4155+
retry-request@5.0.2:
4156+
version "5.0.2"
4157+
resolved "https://registry.yarnpkg.com/retry-request/-/retry-request-5.0.2.tgz#143d85f90c755af407fcc46b7166a4ba520e44da"
4158+
integrity sha512-wfI3pk7EE80lCIXprqh7ym48IHYdwmAAzESdbU8Q9l7pnRCk9LEhpbOTNKjz6FARLm/Bl5m+4F0ABxOkYUujSQ==
4159+
dependencies:
4160+
debug "^4.1.1"
4161+
extend "^3.0.2"
4162+
41554163
retry-request@^4.0.0:
41564164
version "4.1.3"
41574165
resolved "https://registry.yarnpkg.com/retry-request/-/retry-request-4.1.3.tgz#d5f74daf261372cff58d08b0a1979b4d7cab0fde"

0 commit comments

Comments
 (0)