Open tmcw opened 2 months ago
4.28.1
5.6.0
v20.16.0
macOS
14.6.1 (23G93)
This module exports a class at httpErrors.HttpError, so I should be able to write an errorHandler in fastify like this:
httpErrors.HttpError
errorHandler(error, _request, reply) { if (error instanceof httpErrors.HttpError) { return error; } return reply.internalServerError(); }
However, this doesn't type-check: httpErrors.HttpError is an interface in the type exports:
https://github.com/fastify/fastify-sensible/blob/822ae7a895e7e8296429ea38e2cf4060aaf19144/lib/httpError.d.ts#L1-L9
And you can't instanceof an interface, because it's a type, not a value. Most likely, HttpError should be a class.
instanceof
No response
Can you provide a PR?
Yep, I'm trying to, it's turning out to be tricky to implement.
I have created a PR @Uzlopak Please review
Prerequisites
Fastify version
4.28.1
Plugin version
5.6.0
Node.js version
v20.16.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.6.1 (23G93)
Description
This module exports a class at
httpErrors.HttpError
, so I should be able to write an errorHandler in fastify like this:However, this doesn't type-check:
httpErrors.HttpError
is an interface in the type exports:https://github.com/fastify/fastify-sensible/blob/822ae7a895e7e8296429ea38e2cf4060aaf19144/lib/httpError.d.ts#L1-L9
And you can't
instanceof
an interface, because it's a type, not a value. Most likely, HttpError should be a class.Link to code that reproduces the bug
No response
Expected Behavior
No response