Skip to content
Open
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function createError () {
deprecate('non-error status code; use only 4xx or 5xx status codes')
}

if (typeof status !== 'number' ||
if (typeof status !== 'number' || isNaN(status) ||
(!statuses.message[status] && (status < 400 || status >= 600))) {
status = 500
}
Expand Down
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ describe('createError(status)', function () {
assert.strictEqual(this.error.statusCode, 599)
})
})

describe('when status is NaN', function () {
before(function () {
this.error = createError(NaN)
})

it('should have "message" property of "Internal Server Error"', function () {
assert.strictEqual(this.error.message, 'Internal Server Error')
})

it('should have "name" property of "InternalServerError"', function () {
assert.strictEqual(this.error.name, 'InternalServerError')
})

it('should have "status" property of 500', function () {
assert.strictEqual(this.error.status, 500)
})

it('should have "statusCode" property of 500', function () {
assert.strictEqual(this.error.statusCode, 500)
})
})
})

describe('createError(status, message)', function () {
Expand Down