diff --git a/lib/router.js b/lib/router.js index 14c11fa..e186ab5 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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 diff --git a/test/router.js b/test/router.js index 7600c2c..8baab72 100644 --- a/test/router.js +++ b/test/router.js @@ -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) + }) })