-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
docs: added note on handling of invalid URLs in setNotFoundHandler #5661
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
base: main
Are you sure you want to change the base?
Conversation
docs/Reference/Server.md
Outdated
| is passed to `fastify.register()`. The handler is treated as a regular route | ||
| handler so requests will go through the full [Fastify | ||
| lifecycle](./Lifecycle.md#lifecycle). *async-await* is supported as well. | ||
| lifecycle](./Lifecycle.md#lifecycle) for valid URLs. Invalid URLs are sent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is accurate. If a path does not match any configured routes, the request is not passed to a route handler. It is instead handled by the configured 404 handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are 💯 right, I meant to write "directly to the 404 handler" but that last part got removed. With that in place it would be accurate, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that would be accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One things which I have failed to add here, is that in v5 there is a change in that "bad URLs" are no longer sent to the handler but must be dealt with by adding a .frameworkErrors handler if you need to do handle them in a specific manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Signed-off-by: Manuel Spigolon <behemoth89@gmail.com>
I was struggling to understand why a bad URL did not go through the lifecycle like the documentation says. Turns out it doesn't as the router returns directly to the
setNotFoundHandlerin the case of a bad URL.Adding this small note will save others from having to dig down into the router 😄
Checklist
npm run testandnpm run benchmarkand the Code of conduct