Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot subclass errors #101

Closed
cdignam-segment opened this issue Oct 23, 2023 · 1 comment
Closed

Cannot subclass errors #101

cdignam-segment opened this issue Oct 23, 2023 · 1 comment

Comments

@cdignam-segment
Copy link

I was surprised I couldn't subclass errors. I would have expected my ValidationError class would support an instanceof check against itself.

const { BadRequest } = require('http-errors')
const assert = require('assert')


class ValidationError extends BadRequest {}

const err = new ValidationError()
console.log(err.name)
// "BadRequestError"

// err should be an instance of ValidationError
assert(err instanceof ValidationError)

https://runkit.com/cdignam-segment/6536e492c20c690008824a73

@jonchurch
Copy link
Member

duplicate of #98, but yes duly noted. I would expect this to work this way as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants