Skip to content

Commit

Permalink
fix: server should fire not acceptable event (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonutEspresso committed Mar 20, 2018
1 parent 7132fda commit 8b11b71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/plugins/accept.js
Expand Up @@ -48,12 +48,9 @@ function acceptParser(accepts) {

function parseAccept(req, res, next) {
if (req.accepts(acceptable)) {
next();
return;
return next();
}

res.json(e);
next(false);
return next(e);
}

return parseAccept;
Expand Down
23 changes: 23 additions & 0 deletions test/plugins/accept.test.js
Expand Up @@ -68,4 +68,27 @@ describe('accept parser', function() {
done();
});
});

it('GH-1619: should fire NotAcceptable event on server', function(done) {
var opts = {
path: '/',
headers: {
accept: 'foo/bar'
}
};
var evtFired = false;

SERVER.on('NotAcceptable', function(req, res, err, cb) {
evtFired = true;
return cb();
});

CLIENT.get(opts, function(err, _, res) {
assert.ok(err);
assert.equal(err.name, 'NotAcceptableError');
assert.equal(res.statusCode, 406);
assert.isTrue(evtFired);
return done();
});
});
});

0 comments on commit 8b11b71

Please sign in to comment.