diff --git a/lib/methods.js b/lib/methods.js index 54de366b0..7291d4bff 100755 --- a/lib/methods.js +++ b/lib/methods.js @@ -96,16 +96,8 @@ internals.Methods.prototype._add = function (name, method, options, realm) { // Promise object - const onFulfilled = Hoek.nextTick((outcome) => { - - return methodNext(null, outcome); - }); - - const onRejected = Hoek.nextTick((err) => { - - return methodNext(err); - }); - + const onFulfilled = (outcome) => methodNext(null, outcome); + const onRejected = (err) => methodNext(err); result.then(onFulfilled, onRejected); }; } diff --git a/lib/protect.js b/lib/protect.js index 84370ac78..e69d63bb8 100755 --- a/lib/protect.js +++ b/lib/protect.js @@ -52,16 +52,14 @@ internals.Protect.prototype.run = function (next, enter) { // enter return next(arg0, arg1, arg2); }); - if (!this.domain) { - return enter(finish); - } + if (this.domain) { + this._error = (err) => { - this._error = (err) => { - - return finish(Boom.badImplementation('Uncaught error', err)); - }; + return finish(Boom.badImplementation('Uncaught error', err)); + }; + } - this.domain.bind(enter)(finish); + return enter(finish); }; diff --git a/lib/reply.js b/lib/reply.js index aa198f801..3648bb924 100755 --- a/lib/reply.js +++ b/lib/reply.js @@ -122,11 +122,8 @@ internals.continue = function (data) { } } - Hoek.nextTick(() => { - - this._next(null); - this._next = null; - })(); + this._next(null); + this._next = null; }; diff --git a/lib/response.js b/lib/response.js index b0483965e..58c6d3eb4 100755 --- a/lib/response.js +++ b/lib/response.js @@ -453,7 +453,7 @@ internals.Response.prototype._prepare = function (next) { return this._processPrepare(next); } - const onDone = Hoek.nextTick((source) => { + const onDone = (source) => { if (source instanceof Error) { return next(Boom.wrap(source)); @@ -466,7 +466,7 @@ internals.Response.prototype._prepare = function (next) { this._setSource(source); this._passThrough(); this._processPrepare(next); - }); + }; const onError = (source) => { diff --git a/test/request.js b/test/request.js index ab90bc933..03396af0c 100755 --- a/test/request.js +++ b/test/request.js @@ -709,50 +709,6 @@ describe('Request', () => { }); }); - it('emits request-error on implementation error with a promise in pre handler', (done) => { - - const server = new Hapi.Server({ debug: false }); - server.connection({ routes: { log: true } }); - - let errs = 0; - let req = null; - server.on('request-error', (request, err) => { - - ++errs; - expect(err).to.exist(); - expect(err.message).to.equal('Uncaught error: boom'); - req = request; - }); - - const handler = function (request, reply) { - - throw new Error('boom'); - }; - - server.route({ method: 'GET', path: '/', handler }); - - server.ext('onPreHandler', (request, reply) => { - - Promise.resolve() - .then(() => reply.continue()) - .catch(() => reply(Boom.badImplementation('oops'))); - }); - - server.once('response', () => { - - expect(errs).to.equal(1); - expect(req.getLog('error')[0].tags).to.equal(['internal', 'implementation', 'error']); - done(); - }); - - server.inject('/', (res) => { - - expect(res.statusCode).to.equal(500); - expect(res.result).to.exist(); - expect(res.result.message).to.equal('An internal server error occurred'); - }); - }); - it('does not emit request-error when error is replaced with valid response', (done) => { const server = new Hapi.Server({ debug: false });