Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Unreleased changes
2.0.1 / 2025-11-20
==================

* improve toClassName function readability and JSDoc completeness
* deps: use tilde notation for dependencies
* deps: update statuses to 2.0.2

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ function createError () {

function createHttpErrorConstructor () {
function HttpError () {
throw new TypeError('cannot construct abstract class')
if (this.constructor === HttpError) {
throw new TypeError('cannot construct abstract class')
}
}

inherits(HttpError, Error)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "http-errors",
"description": "Create HTTP error objects",
"version": "2.0.0",
"version": "2.0.1",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",
"contributors": [
"Alan Plum <me@pluma.io>",
Expand Down
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,28 @@ describe('HTTP Errors', function () {
assert((new createError['500']()) instanceof createError.HttpError)
})

it('should interoperate with ES6 classes', function () {
class MyHttpError extends createError.HttpError {
constructor () {
super()
this.name = 'MyHttpError'
this.message = 'ES6 class HTTPError'
this.status = 404
this.myProp = 'test'
}
}

// Testing PR#99: This line should not throw TypeError('cannot construct abstract class')
const err = new MyHttpError()
assert.strictEqual(err.name, 'MyHttpError')
assert.strictEqual(err.message, 'ES6 class HTTPError')
assert.strictEqual(err.status, 404)
assert.strictEqual(err.myProp, 'test')
/* eslint-disable-next-line node/no-deprecated-api */
assert.strictEqual(util.isError(err), true)
assert.strictEqual(createError.isHttpError(err), true)
})

itUtilIsError('should support util.isError()', function () {
/* eslint-disable node/no-deprecated-api */
assert(util.isError(createError(404)))
Expand Down