The superagent lib will abort the request before retry, and the error code will be ECONNABORTED. So I suggest that add a retry at the retries.js. This error code was added at the superagent source code. https://github.com/visionmedia/superagent/blob/master/lib/should-retry.js
/**
* Request be aborted
*/
function econnabort (err, res) {
return err && err.code === 'ECONNABORTED';
}
In addition, if ECONNABORTED is added, one issue should be attention.
Some code like following:
request.get('xxxx')
.timeout(5000)
.retry(2)
.end((err, res) => {
// TODO
})
when first time the request is aborted, the this._aborted will be true, and next time retry request, the request will be return. Show the code.
// https://github.com/visionmedia/superagent/blob/master/lib/request-base.js
RequestBase.prototype._timeoutError = function(reason, timeout, errno){
if (this._aborted) { // The second time here is true.
return;
}
var err = new Error(reason + timeout + 'ms exceeded');
err.timeout = timeout;
err.code = 'ECONNABORTED';
err.errno = errno;
this.timedout = true;
this.abort();
this.callback(err);
};
So we can fix it at reset function.
// https://github.com/segmentio/superagent-retry/blob/master/lib/index.js
/**
* HACK: Resets the internal state of a request.
*/
function reset (request, timeout) {
var headers = request.req._headers;
var path = request.req.path;
request.req.abort();
request.called = false;
request._aborted = false; // code is here
request.timeout(timeout);
delete request.req;
delete request._timer;
...
}
The superagent lib will abort the request before retry, and the error code will be ECONNABORTED. So I suggest that add a retry at the
retries.js. This error code was added at the superagent source code. https://github.com/visionmedia/superagent/blob/master/lib/should-retry.jsIn addition, if ECONNABORTED is added, one issue should be attention.
Some code like following:
when first time the request is aborted, the
this._abortedwill be true, and next time retry request, the request will be return. Show the code.So we can fix it at
resetfunction.