Open FrancoRATOVOSON opened 4 months ago
Do not rely on the instanceof
operator https://github.com/fastify/fastify-error/pull/86#issuecomment-1301466407
Do not rely on the
instanceof
operator fastify/fastify-error#86 (comment)
https://github.com/fastify/fastify-error/pull/86#issuecomment-1301339441 is supposed to be the best solution
If somebody wants all Fastify core errors, they can do err.code?.indexOf('FST_') === 0.
But that doesn't really help with errorResponse
especialy with typescript when the type of the error is Error
and property code
does not exist on this type
Prerequisites
🚀 Feature Proposal
I have my custom way to handle errors depending on their type. I know that by using
verifyBearerAuth
there are 2 types of errors that can be thrown and I have a custom way to handle booth cases separately. But now I cannot check if the error is anFST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER
or anFST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER
because none of them is exportedMotivation
Handling errors a custom way.
Example