Skip to content

Allow HttpError extension by ES6 classes #98

@nathanlepori

Description

@nathanlepori

To allow better interoperability with ES6 classes (which are forced to call the super() constructor) it is better to add the following condition to the HttpError constructor:

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

This way the class can be extended with a concrete class like this:

class MyHttpError extends HttpError {
    constructor() {
        super();
        ...
    }
}

A variant using ES6 classes as base class is shown here but the same works with old school constructor functions as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions