Skip to content

Commit

Permalink
Improve error message when req argument missing
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jun 13, 2015
1 parent 57b9f4b commit 8c9e7f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==========

* Improve error message when `req` argument missing
* perf: enable strict mode
* perf: hoist regular expression
* perf: parse with regular expressions
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var userPassRegExp = /^([^:]*):(.*)$/
*/

function auth(req) {
if (!req) {
throw new TypeError('argument req is required')
}

// get header
var header = (req.req || req).headers.authorization

Expand Down
10 changes: 9 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ function request(authorization) {
}
}

describe('auth(req)', function(){
describe('auth(req)', function () {
describe('arguments', function () {
describe('req', function () {
it('should be required', function () {
assert.throws(auth, /argument req is required/)
})
})
})

describe('with no Authorization field', function(){
it('should return null', function(){
var req = request();
Expand Down

0 comments on commit 8c9e7f9

Please sign in to comment.