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

Remove reference to request in domain. Closes #1634 #1635

Merged
merged 2 commits into from
May 13, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions lib/protect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ var Utils = require('./utils');
var internals = {};


exports = module.exports = internals.Protect = function (parent) {
exports = module.exports = internals.Protect = function (request) {

var self = this;

this._error = null;
this.request = request;

this.domain = Domain.create();
this.domain.on('error', function (err) {
Expand All @@ -25,7 +26,12 @@ exports = module.exports = internals.Protect = function (parent) {
return handler(err);
}

parent.log(['hapi', 'internal', 'implementation', 'error'], err);
if (self.request) {
self.request.log(['hapi', 'internal', 'implementation', 'error'], err);
}
else {
console.error('Debug: late request implementation error:\n ' + err.stack);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this make it to a centralized log rather than console log? We for example don't have those going anywhere and no monitoring to speak of on console.

}
});
};

Expand Down
2 changes: 2 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ internals.Request.prototype._finalize = function () {
if (this.response._close) {
this.response._close();
}

this._protect.request = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is it safer to have a cleanup/close/dispose/whatever operation? This way the request object doesn't need to be aware of the internals of the protect object.

};


Expand Down
27 changes: 27 additions & 0 deletions test/protect.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,31 @@ describe('Protect', function () {
});
});
});

it('logs to console after request completed', { parallel: false }, function (done) {

var orig = console.error;
console.error = function () {

console.error = orig;
expect(arguments[0]).to.contain('Debug: late request implementation error:\n Error: After done');
done();
};

var handler = function (request, reply) {

reply('ok');
setTimeout(function () {

throw new Error('After done');
}, 10);
};

var server = new Hapi.Server({ debug: false });
server.route({ method: 'GET', path: '/', handler: handler });
server.inject('/', function (res) {

expect(res.statusCode).to.equal(200);
});
});
});