Skip to content

Commit 2d1c598

Browse files
Micheal Hillfengmk2
Micheal Hill
authored andcommitted
feat: export HttpError from http-errors library
1 parent cf70dbc commit 2d1c598

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/application.js

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const http = require('http');
2121
const only = require('only');
2222
const convert = require('koa-convert');
2323
const deprecate = require('depd')('koa');
24+
const { HttpError } = require('http-errors');
2425

2526
/**
2627
* Expose `Application` class.
@@ -257,3 +258,9 @@ function respond(ctx) {
257258
}
258259
res.end(body);
259260
}
261+
262+
/**
263+
* Make HttpError available to consumers of the library so that consumers don't
264+
* have a direct dependency upon `http-errors`
265+
*/
266+
module.exports.HttpError = HttpError;

test/application/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ describe('app', () => {
7777
const app = new Koa({ subdomainOffset });
7878
assert.strictEqual(app.subdomainOffset, subdomainOffset);
7979
});
80+
81+
it('should have a static property exporting `HttpError` from http-errors library', () => {
82+
const CreateError = require('http-errors');
83+
84+
assert.notEqual(Koa.HttpError, undefined);
85+
assert.deepStrictEqual(Koa.HttpError, CreateError.HttpError);
86+
assert.throws(() => { throw new CreateError(500, 'test error'); }, Koa.HttpError);
87+
});
8088
});

0 commit comments

Comments
 (0)