Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errno for timeouts #1184

Merged
merged 1 commit into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/request-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,14 @@ RequestBase.prototype.sortQuery = function(sort) {
* @api private
*/

RequestBase.prototype._timeoutError = function(reason, timeout){
RequestBase.prototype._timeoutError = function(reason, timeout, errno){
if (this._aborted) {
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);
Expand All @@ -572,13 +573,13 @@ RequestBase.prototype._setTimeouts = function() {
// deadline
if (this._timeout && !this._timer) {
this._timer = setTimeout(function(){
self._timeoutError('Timeout of ', self._timeout);
self._timeoutError('Timeout of ', self._timeout, 'ETIME');
}, this._timeout);
}
// response timeout
if (this._responseTimeout && !this._responseTimeoutTimer) {
this._responseTimeoutTimer = setTimeout(function(){
self._timeoutError('Response timeout of ', self._responseTimeout);
self._timeoutError('Response timeout of ', self._responseTimeout, 'ETIMEDOUT');
}, this._responseTimeout);
}
}
2 changes: 2 additions & 0 deletions test/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('.timeout(ms)', function(){
.end(function(err, res){
assert(err, 'expected an error');
assert.equal('ECONNABORTED', err.code, 'expected abort error code')
assert.equal('ETIME', err.errno);
done();
});
});
Expand All @@ -76,6 +77,7 @@ describe('.timeout(ms)', function(){
assert(err, 'expected an error');
assert.equal('number', typeof err.timeout, 'expected an error with .timeout');
assert.equal('ECONNABORTED', err.code, 'expected abort error code')
assert.equal('ETIMEDOUT', err.errno);
done();
});
});
Expand Down