Skip to content

Commit

Permalink
Revert #3202
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Aug 26, 2016
1 parent 4278425 commit 468f78c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 69 deletions.
12 changes: 2 additions & 10 deletions lib/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
Expand Down
14 changes: 6 additions & 8 deletions lib/protect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};


Expand Down
7 changes: 2 additions & 5 deletions lib/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,8 @@ internals.continue = function (data) {
}
}

Hoek.nextTick(() => {

this._next(null);
this._next = null;
})();
this._next(null);
this._next = null;
};


Expand Down
4 changes: 2 additions & 2 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -466,7 +466,7 @@ internals.Response.prototype._prepare = function (next) {
this._setSource(source);
this._passThrough();
this._processPrepare(next);
});
};

const onError = (source) => {

Expand Down
44 changes: 0 additions & 44 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 468f78c

Please sign in to comment.