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
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ module.exports = assert

function assert (value, status, msg, opts) {
if (value) return
throw createError(status, msg, opts)
var args = [status]
if (msg !== undefined) args.push(msg)
if (opts !== undefined) args.push(opts)
throw createError.apply(null, args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change here ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a breaking change? How does it change the behaviour for users of http-assert?

}

assert.fail = function (status, msg, opts) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"repository": "jshttp/http-assert",
"dependencies": {
"deep-equal": "~1.0.1",
"http-errors": "~1.8.0"
"http-errors": "~2.0.1"
},
"devDependencies": {
"eslint": "7.32.0",
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ describe('assert()', function () {
ok(!err.expose)
})

it('should accept options for the error object when msg is undefined', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have the tests matching the new setup? this is not testing the two new operation / conditions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What isn't covered by the tests?

var err

try {
assert(false, 401, undefined, { expose: false })
} catch (e) {
err = e
}

ok(err)
ok(err.status === 401)
ok(err.message === 'Unauthorized')
ok(!err.expose)
})

it('should not expose 5xx errors', function () {
var err

Expand Down