async-retry is a promisified version of retry which makes things easier with the async-await syntax.
Get it:npm install async-retry
Sample usage:
12345678910111213141516171819
// Packages constretry=require('async-retry')constfetch=require('node-fetch')awaitretry(asyncbail=>{// if anything throws, we retry constres=awaitfetch('https://google.com')if(403===res.status){// don't retry upon 403 bail(newError('Unauthorized'))return}constdata=awaitres.text()returndata.substr(0,500)},{retries:500})