http-request-retry
v1.0.4
Published
request can retry if fail
Downloads
8
Maintainers
Readme
http-request-retry
http-request-retry
- Config request can retry n time if has error.
- It has small dependencies include lodash and request.
Install module
npm install http-request-retry --save
Step 1: import module
let httpService = require('http-request-retry');
Step 2: config module
httpService.config({
debug: false, //log consle if error
delay: 1000, //waiting time between each retry
});
Step 3: repair options
let options = {
url: `url request`, // required; url request Ex: http://abc.com https://abc.com
method: "GET", //required; default POST
headers: {}, //optional Ex: { 'Content-Type': 'application/json; charset=UTF-8' }
retry:3, //optional; type NUMBER
timeout: 5000, //optional; request timeout; default 60000
};
Step 4: excute
httpService.requestPromise(options).then(res=>{
console.log(res);
}).catch(err=>{
console.error(err);
})
Or
httpService.requestCallback(options,(err, result)=>{
if(err){
console.log(`Final err`, err);
}
});