こんにちは、
下記コードにおいて、エラーまたはタイムアウトが発生した場合に3回retryをしたいのですが、どのように記述すればいいのかわかりません。
retryライブラリを使えばいいのはわかるのですが、、、ご教授願います。
node
1var https = require('https'); 2var querystring = require('querystring'); 3 4exports.httpRequest = function (callback) { 5const postData = querystring.stringify({ 6 'msg': 'Hello World!' 7}); 8 9const options = { 10 hostname: 'www.google.com', 11 port: 80, 12 path: '/upload', 13 method: 'POST', 14 headers: { 15 'Content-Type': 'application/x-www-form-urlencoded', 16 'Content-Length': Buffer.byteLength(postData) 17 } 18}; 19 20const req = http.request(options, (res) => { 21 console.log(`STATUS: ${res.statusCode}`); 22 console.log(`HEADERS: ${JSON.stringify(res.headers)}`); 23 res.setEncoding('utf8'); 24 res.on('data', (chunk) => { 25 console.log(`BODY: ${chunk}`); 26 }); 27 res.on('end', () => { 28 console.log('No more data in response.'); 29 callback(); 30 }); 31}); 32 33req.on('error', (e) => { 34 console.log(`problem with request: ${e.message}`); 35}); 36 37// write data to request body 38req.write(postData); 39req.end(); 40};

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。