diff --git a/.eslintrc.js b/.eslintrc.js index 561303c..f036431 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -22,7 +22,6 @@ module.exports = { 'node/global-require': 0, 'promise/no-callback-in-promise': 0, 'promise/prefer-await-to-callbacks': 0, - 'promise/prefer-await-to-then': 0, 'unicorn/filename-case': 0, }, overrides: [...overrides], diff --git a/src/deploy/hasher-segments.js b/src/deploy/hasher-segments.js index 5f38877..006cc18 100644 --- a/src/deploy/hasher-segments.js +++ b/src/deploy/hasher-segments.js @@ -10,12 +10,14 @@ const { normalizePath } = require('./util') const hasherCtor = ({ concurrentHash, hashAlgorithm = 'sha1' }) => { const hashaOpts = { algorithm: hashAlgorithm } if (!concurrentHash) throw new Error('Missing required opts') - return transform(concurrentHash, { objectMode: true }, (fileObj, cb) => { - hasha - .fromFile(fileObj.filepath, hashaOpts) + return transform(concurrentHash, { objectMode: true }, async (fileObj, cb) => { + try { + const hash = await hasha.fromFile(fileObj.filepath, hashaOpts) // insert hash and asset type to file obj - .then((hash) => cb(null, { ...fileObj, hash })) - .catch((error) => cb(error)) + return cb(null, { ...fileObj, hash }) + } catch (error) { + return cb(error) + } }) } diff --git a/src/deploy/upload-files.js b/src/deploy/upload-files.js index 5e4013f..5873af4 100644 --- a/src/deploy/upload-files.js +++ b/src/deploy/upload-files.js @@ -75,22 +75,19 @@ const retryUpload = (uploadFn, maxRetry) => maxDelay: 90000, }) - const tryUpload = () => { - uploadFn() - .then((results) => resolve(results)) - .catch((error) => { - lastError = error - switch (true) { - // observed errors: 408, 401 (4** swallowed), 502 - case error.status >= 400: - case error.name === 'FetchError': { - return fibonacciBackoff.backoff() - } - default: { - return reject(error) - } - } - }) + const tryUpload = async () => { + try { + const results = await uploadFn() + return resolve(results) + } catch (error) { + lastError = error + // observed errors: 408, 401 (4** swallowed), 502 + if (error.status >= 400 || error.name === 'FetchError') { + fibonacciBackoff.backoff() + return + } + return reject(error) + } } fibonacciBackoff.failAfter(maxRetry)