Skip to content

Commit

Permalink
Merge pull request hapijs#432 from wpreul/bug/431
Browse files Browse the repository at this point in the history
Error responses skip response validation
  • Loading branch information
Eran Hammer committed Jan 31, 2013
2 parents ffabc33 + 56d80c3 commit 6fbb7f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ exports.response = function (request, next) {
}
}

if (request._response instanceof Error) {
return next();
}

if (request._response instanceof Response.Obj === false) {
return next(Err.internal('Cannot validate non-object response'));
}
Expand Down
14 changes: 14 additions & 0 deletions test/unit/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ describe('Validation', function () {
});
});

it('an error response should skip response validation and not return an error', function (done) {

var query = { username: 'walmart' };
var request = createRequestObject(query, route);

request._response = Hapi.Response.generate(Hapi.Error.unauthorized('You are not authorized'));

Validation.response(request, function (err) {

expect(err).to.not.exist;
done();
});
});

it('should raise an error when responding with invalid param', function (done) {

var query = { username: 'walmart' };
Expand Down

0 comments on commit 6fbb7f8

Please sign in to comment.