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:
Buddy Sandidge 2016-02-07 22:01:02 -08:00
parent f89bc55105
commit 62e6469ec7
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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)
})
})