From 2d1c5981869e0fe6f5bc71b5c5582accfd125cc6 Mon Sep 17 00:00:00 2001 From: Micheal Hill Date: Fri, 16 Mar 2018 09:34:55 +1100 Subject: [PATCH] feat: export HttpError from http-errors library --- lib/application.js | 7 +++++++ test/application/index.js | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/application.js b/lib/application.js index 098ecb16c..6415444da 100644 --- a/lib/application.js +++ b/lib/application.js @@ -21,6 +21,7 @@ const http = require('http'); const only = require('only'); const convert = require('koa-convert'); const deprecate = require('depd')('koa'); +const { HttpError } = require('http-errors'); /** * Expose `Application` class. @@ -257,3 +258,9 @@ function respond(ctx) { } res.end(body); } + +/** + * Make HttpError available to consumers of the library so that consumers don't + * have a direct dependency upon `http-errors` + */ +module.exports.HttpError = HttpError; diff --git a/test/application/index.js b/test/application/index.js index ff2711175..ec5ea25b1 100644 --- a/test/application/index.js +++ b/test/application/index.js @@ -77,4 +77,12 @@ describe('app', () => { const app = new Koa({ subdomainOffset }); assert.strictEqual(app.subdomainOffset, subdomainOffset); }); + + it('should have a static property exporting `HttpError` from http-errors library', () => { + const CreateError = require('http-errors'); + + assert.notEqual(Koa.HttpError, undefined); + assert.deepStrictEqual(Koa.HttpError, CreateError.HttpError); + assert.throws(() => { throw new CreateError(500, 'test error'); }, Koa.HttpError); + }); });