Skip to content

Commit

Permalink
Fix timeout value
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrado Quilles Gomes committed Jul 28, 2020
1 parent 90853ef commit 404008c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function linkCheck(link, opts, callback) {
opts = {};
}

opts.timeout = opts.timeout || '10s';
opts.timeout = opts.timeout || 10000;
opts.retryOn429 = opts.retryOn429 || false;
opts.allwaysRetry = opts.allwaysRetry || false;
opts.aliveStatusCodes = opts.aliveStatusCodes || [ 200 ];
Expand Down
13 changes: 4 additions & 9 deletions lib/proto/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,15 @@ module.exports = {
}

request.head(options, function (err, res, body) {
console.log('Error')
console.dir(err);
console.log('Res')
console.dir(res);
if (err) console.dir(err);
if (!err && res.statusCode === 200) {
callback(null, new LinkCheckResult(opts, link, res.statusCode, err)); // alive, returned 200 OK
return;
}

// if HEAD fails (405 Method Not Allowed, etc), try GET
request.get(options, function (err, res) {
console.log('Error')
console.dir(err);
console.log('Res')
console.dir(res);
if (err) console.dir(err);
// If enabled in opts, the response was a 429 (Too Many Requests) and there is a retry-after provided, wait and then retry
if (opts.retryOn429 && res && res.statusCode === 429 && res.headers.hasOwnProperty('retry-after') && attempts < 2) {
const retryStr = res.headers['retry-after'];
Expand Down Expand Up @@ -75,7 +69,8 @@ module.exports = {
setTimeout(check, retryInMs, link, opts, callback, attempts + 1);
} else if (opts.allwaysRetry && res && res.statusCode === 0 && attempts < 2) {
setTimeout(check, 2000, link, opts, callback, attempts + 1);
} else {
} else {
if (res && res.statusCode == 0) console.dir(res);
callback(null, new LinkCheckResult(opts, link, res ? res.statusCode : 0, err));
}
}).pipe(new BlackHole());
Expand Down

0 comments on commit 404008c

Please sign in to comment.