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

Please exports your errors type #182

Open
2 tasks done
FrancoRATOVOSON opened this issue Jun 19, 2024 · 2 comments
Open
2 tasks done

Please exports your errors type #182

FrancoRATOVOSON opened this issue Jun 19, 2024 · 2 comments

Comments

@FrancoRATOVOSON
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 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 an FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER or an FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER because none of them is exported

Motivation

Handling errors a custom way.

Example

if(error instanceof FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER) {
  // handle missing authorization header
} else if (error instance of FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER) {
  // handle invalid token
} else {
 // Probably a 500 error or any you have defined
}
@jsumners
Copy link
Member

jsumners commented Jun 19, 2024

Do not rely on the instanceof operator fastify/fastify-error#86 (comment)

@FrancoRATOVOSON
Copy link
Author

Do not rely on the instanceof operator fastify/fastify-error#86 (comment)

fastify/fastify-error#86 (comment) 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

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