Skip to content

Commit 8c9e7f9

Browse files
committed
Improve error message when req argument missing
1 parent 57b9f4b commit 8c9e7f9

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Improve error message when `req` argument missing
45
* perf: enable strict mode
56
* perf: hoist regular expression
67
* perf: parse with regular expressions

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ var userPassRegExp = /^([^:]*):(.*)$/
4646
*/
4747

4848
function auth(req) {
49+
if (!req) {
50+
throw new TypeError('argument req is required')
51+
}
52+
4953
// get header
5054
var header = (req.req || req).headers.authorization
5155

test/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ function request(authorization) {
99
}
1010
}
1111

12-
describe('auth(req)', function(){
12+
describe('auth(req)', function () {
13+
describe('arguments', function () {
14+
describe('req', function () {
15+
it('should be required', function () {
16+
assert.throws(auth, /argument req is required/)
17+
})
18+
})
19+
})
20+
1321
describe('with no Authorization field', function(){
1422
it('should return null', function(){
1523
var req = request();

0 commit comments

Comments
 (0)