You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds c.isNotFound. It is true if the Not Found handler (c.notFound()) is called.
app.use(async(c,next)=>{awaitnext()if(c.isNotFound){// no route matched, or a handler called `c.notFound()`}})
Until now, there was no way to know if a Response came from c.notFound(). For example, if you check the status code 404, you can't tell it from c.json({ ... }, 404). With this PR, c.isNotFound is true if the Not Found handler was called. It is like c.error for onError.
With this, you can write a Not Found page for a sub app or a path in a middleware:
When a loader returns c.notFound(), Void wants to render its own 404 page in the layout of the route. With #5686, a Response from the handler is passed to respondWith(), so Void can check c.isNotFound there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds
c.isNotFound. It istrueif the Not Found handler (c.notFound()) is called.Until now, there was no way to know if a Response came from
c.notFound(). For example, if you check the status code404, you can't tell it fromc.json({ ... }, 404). With this PR,c.isNotFoundistrueif the Not Found handler was called. It is likec.errorforonError.With this, you can write a Not Found page for a sub app or a path in a middleware:
It also solves the problem in Void that @ashunar0 found: #5685 (comment)
When a loader returns
c.notFound(), Void wants to render its own 404 page in the layout of the route. With #5686, a Response from the handler is passed torespondWith(), so Void can checkc.isNotFoundthere.c.notFoundto know that it was calledc.json({ ... }, 404)from the loader is not changed to the 404 pageThe author should do the following, if applicable
pnpm run check:fixto format and lint the code