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

How to import fastify error codes? #4250

Closed
3 tasks
Eomm opened this issue Sep 3, 2022 Discussed in #3842 · 7 comments · Fixed by #4266
Closed
3 tasks

How to import fastify error codes? #4250

Eomm opened this issue Sep 3, 2022 Discussed in #3842 · 7 comments · Fixed by #4266
Labels
good first issue Good for newcomers

Comments

@Eomm
Copy link
Member

Eomm commented Sep 3, 2022

Discussed in #3842

Originally posted by teemupiiroinenwirepas April 20, 2022
We would like to map fastify error codes from https://github.com/fastify/fastify/blob/main/lib/errors.js to our own error codes, but we cannot find a way how to import the codes. How the importing should be done, or how the error code mapping should be done to the application specific error codes?

Br,
Teemu


We should:

@Eomm Eomm added the good first issue Good for newcomers label Sep 3, 2022
@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 3, 2022

Also dont forget that fastify plugins have their own errors. Maybe we should register those errors also?

@fitiskin
Copy link
Contributor

fitiskin commented Sep 4, 2022

I'd like to do this. Assign it to me please, if @teemupiiroinenwirepas don't mind.

@Eomm
Copy link
Member Author

Eomm commented Sep 4, 2022

Maybe we should register those errors also?

This integration would be nice, but it should be transparent for the @fastify/errors users

@mcollina
Copy link
Member

mcollina commented Sep 4, 2022

Let's not include plugins.

@fitiskin
Copy link
Contributor

fitiskin commented Sep 7, 2022

I can't understand how this frameworkErrors example is supposed to work while we can't import FST_ERR_BAD_URL directly.

@fitiskin
Copy link
Contributor

fitiskin commented Sep 7, 2022

Should we export only error codes (string names) or the errors produced by createError?

Error codes:

const fastify = require('fastify')

exampleErrorHandler((err) => {
    if (err.code === fastify.errorCodes.FST_ERR_NOT_FOUND) {
        //
    }
})

Errors:

const fastify = require('fastify')

exampleErrorHandler((err) => {
    if (err instanceof fastify.errorCodes.FST_ERR_NOT_FOUND) {
        //
    }
})

As I guess we shouldn't export the appendStackTrace utility function.

@Eomm
Copy link
Member Author

Eomm commented Sep 9, 2022

Should we export only #3842 (reply in thread) (string names) or the errors produced by createError?

The latter 👍🏽

As I guess we shouldn't export the appendStackTrace utility function.

Yes, there is not value for the user getting it

@fitiskin fitiskin mentioned this issue Sep 11, 2022
4 tasks
@Eomm Eomm linked a pull request Sep 24, 2022 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants