Skip to content

Commit

Permalink
Handle invalid status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jun 19, 2014
1 parent 9d2d23e commit a75d6a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Handle invalid status codes

0.0.1 / 2014-06-05
==================

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function finalhandler(req, res, options) {
// unhandled error
if (err) {
// default status code to 500
if (res.statusCode < 400) {
if (!res.statusCode || res.statusCode < 400) {
res.statusCode = 500
}

Expand Down
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ describe('finalhandler(req, res)', function () {
.expect(414, done)
})
})

describe('when res.statusCode undefined', function () {
it('should set to 500', function (done) {
var server = http.createServer(function (req, res) {
var done = finalhandler(req, res)
res.statusCode = undefined
done(new Error('oops'))
})

request(server)
.get('/foo')
.expect(500, done)
})
})
})

describe('request started', function () {
Expand Down

0 comments on commit a75d6a8

Please sign in to comment.