docs: added note on handling of invalid URLs in setNotFoundHandler#5661
docs: added note on handling of invalid URLs in setNotFoundHandler#5661Eomm merged 6 commits intofastify:mainfrom
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.
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.
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.
Yes, I think that would be accurate.
There was a problem hiding this comment.
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.
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