8000 docs: added note on handling of invalid URLs in setNotFoundHandler by leftieFriele · Pull Request #5661 · fastify/fastify · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@leftieFriele
Copy link
@leftieFriele leftieFriele commented Sep 4, 2024

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 setNotFoundHandler in the case of a bad URL.
Adding this small note will save others from having to dig down into the router 😄

Checklist

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Sep 4, 2024
@leftieFriele leftieFriele changed the title docs: added not in invalid URLs in setNotFoundHandler docs: added note on handling of invalid URLs in setNotFoundHandler Sep 5, 2024
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
Copy link
Member

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.

Copy link
Author
@leftieFriele leftieFriele Oct 8, 2024

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?

Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsumners does it LGTY with the proposed changes 5d2b35b ?

Copy link
Member
@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0