Skip to content

Commit

Permalink
feat: export HttpError from http-errors library
Browse files Browse the repository at this point in the history
  • Loading branch information
Micheal Hill authored and fengmk2 committed Oct 12, 2019
1 parent cf70dbc commit 2d1c598
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
8 changes: 8 additions & 0 deletions test/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 2d1c598

Please sign in to comment.