Add static isNotFound error checker to Router class
If used, it will allow the error message to change without inspecting the error.message
This commit is contained in:
parent
f89bc55105
commit
62e6469ec7
@ -50,7 +50,10 @@ assign(Router.prototype, {
|
||||
return memo.concat(item)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Router.isNotFound = function isNotFound(err) {
|
||||
return err instanceof Error && /not found/.exec(err.message) !== null
|
||||
}
|
||||
|
||||
module.exports = Router
|
||||
|
||||
@ -96,4 +96,16 @@ describe('Router', function () {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('→ check not found error', function (done) {
|
||||
var router = new Router()
|
||||
router.route('/not/real/id', function (err) {
|
||||
expect(Router.isNotFound(err)).toBe(true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('→ check not found error on not real error', function () {
|
||||
expect(Router.isNotFound(new Error('Not the missing error'))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user