Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit 9e1c22f

Browse files
committed
Add promise/prefer-await-to-then ESLint rule
1 parent 23f2140 commit 9e1c22f

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ module.exports = {
2222
'node/global-require': 0,
2323
'promise/no-callback-in-promise': 0,
2424
'promise/prefer-await-to-callbacks': 0,
25-
'promise/prefer-await-to-then': 0,
2625
'unicorn/filename-case': 0,
2726
},
2827
overrides: [...overrides],

src/deploy/hasher-segments.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ const { normalizePath } = require('./util')
1010
const hasherCtor = ({ concurrentHash, hashAlgorithm = 'sha1' }) => {
1111
const hashaOpts = { algorithm: hashAlgorithm }
1212
if (!concurrentHash) throw new Error('Missing required opts')
13-
return transform(concurrentHash, { objectMode: true }, (fileObj, cb) => {
14-
hasha
15-
.fromFile(fileObj.filepath, hashaOpts)
13+
return transform(concurrentHash, { objectMode: true }, async (fileObj, cb) => {
14+
try {
15+
const hash = await hasha.fromFile(fileObj.filepath, hashaOpts)
1616
// insert hash and asset type to file obj
17-
.then((hash) => cb(null, { ...fileObj, hash }))
18-
.catch((error) => cb(error))
17+
return cb(null, { ...fileObj, hash })
18+
} catch (error) {
19+
return cb(error)
20+
}
1921
})
2022
}
2123

src/deploy/upload-files.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,19 @@ const retryUpload = (uploadFn, maxRetry) =>
7575
maxDelay: 90000,
7676
})
7777

78-
const tryUpload = () => {
79-
uploadFn()
80-
.then((results) => resolve(results))
81-
.catch((error) => {
82-
lastError = error
83-
switch (true) {
84-
// observed errors: 408, 401 (4** swallowed), 502
85-
case error.status >= 400:
86-
case error.name === 'FetchError': {
87-
return fibonacciBackoff.backoff()
88-
}
89-
default: {
90-
return reject(error)
91-
}
92-
}
93-
})
78+
const tryUpload = async () => {
79+
try {
80+
const results = await uploadFn()
81+
return resolve(results)
82+
} catch (error) {
83+
lastError = error
84+
// observed errors: 408, 401 (4** swallowed), 502
85+
if (error.status >= 400 || error.name === 'FetchError') {
86+
fibonacciBackoff.backoff()
87+
return
88+
}
89+
return reject(error)
90+
}
9491
}
9592

9693
fibonacciBackoff.failAfter(maxRetry)

0 commit comments

Comments
 (0)