File tree 3 files changed +18
-10
lines changed
3 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 37
37
"recursive-readdir-sync" : " ^1.0.6" ,
38
38
"request" : " ^2.88.0" ,
39
39
"request-promise" : " ^4.2.2" ,
40
+ "retry-request" : " 5.0.2" ,
40
41
"rimraf" : " ^2.7.1"
41
42
},
42
43
"devDependencies" : {
Original file line number Diff line number Diff line change
1
+ const _ = require ( 'lodash' ) ;
1
2
const rp = require ( 'request-promise' ) ;
3
+ const Promise = require ( 'bluebird' ) ;
4
+ const retryRequest = require ( 'retry-request' ) ;
2
5
3
6
class CodefreshAPI {
4
7
5
8
static async sendRequest ( config , opts ) {
6
9
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 ) ;
16
15
}
17
- throw error ;
16
+ return body ;
18
17
}
19
18
return rp ( opts ) ;
20
19
}
Original file line number Diff line number Diff line change @@ -4152,6 +4152,14 @@ restore-cursor@^1.0.1:
4152
4152
exit-hook "^1.0.0"
4153
4153
onetime "^1.0.0"
4154
4154
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
+
4155
4163
retry-request@^4.0.0 :
4156
4164
version "4.1.3"
4157
4165
resolved "https://registry.yarnpkg.com/retry-request/-/retry-request-4.1.3.tgz#d5f74daf261372cff58d08b0a1979b4d7cab0fde"
You can’t perform that action at this time.
0 commit comments