File tree 2 files changed +15
-0
lines changed
2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ const http = require('http');
21
21
const only = require ( 'only' ) ;
22
22
const convert = require ( 'koa-convert' ) ;
23
23
const deprecate = require ( 'depd' ) ( 'koa' ) ;
24
+ const { HttpError } = require ( 'http-errors' ) ;
24
25
25
26
/**
26
27
* Expose `Application` class.
@@ -257,3 +258,9 @@ function respond(ctx) {
257
258
}
258
259
res . end ( body ) ;
259
260
}
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 ;
Original file line number Diff line number Diff line change @@ -77,4 +77,12 @@ describe('app', () => {
77
77
const app = new Koa ( { subdomainOffset } ) ;
78
78
assert . strictEqual ( app . subdomainOffset , subdomainOffset ) ;
79
79
} ) ;
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
+ } ) ;
80
88
} ) ;
You can’t perform that action at this time.
0 commit comments