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

Throw TypeError if argument passed to res.status is null or undefined #3111

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ var res = module.exports = {
*/

res.status = function(code){
if (code == null) {
throw new TypeError('Invalid status code.');
}
this.statusCode = code;
return this;
};
Expand Down
13 changes: 12 additions & 1 deletion test/res.status.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,16 @@ describe('res', function(){
.expect('Created')
.expect(201, done);
})

it('should throw a TypeError if code is null or undefined', function(done){
var app = express();
app.use(function(req, res){
res.status(null).end('Created');
});

request(app)
.get('/')
.expect(500, done);
})
})
})
});