Provide way of forcing a 404
See original GitHub issueLet’s say you have a page file that matches the current route, but upon fetching some data in the addPageContext hook, you determine that necessary data is unavailable and the user should be served with a 404 error page. At present, I believe the only option available to a user here is to halt rendering of the page and render an error would be to throw an error within the addPageContext hook. However, this will end up as a 500, not a 404. In this specific case, we are deliberately throwing an error that we would like to be cast as a 404.
I have a suggestion for how this could be achieved - export error classes that can be imported and used to throw specific error types. E.g.
import { ServerError, NotFoundError } from 'vite-plugin-ssr';
export async function addPageContext({ url }) {
const criticalData = await fetchCriticalData(url);
if (!criticalData) {
throw new NotFoundError;
}
return {
criticalData
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
What Is a 404 Error? How to Deal With the Web Error
A 404 error indicates that the webpage you're trying to reach can't be found, and usually means that the page has moved or...
Read more >How to Fix Error 404 Not Found on Your WordPress Site - Kinsta
The easiest way to fix this is to update your permalink settings through the WordPress dashboard. All you need to do is go...
Read more >Apache: forcing a 404 status code - tomcat - Stack Overflow
I need to figure out a way to make these return a 404 so that these URLs drop out of the search engine...
Read more >How to Create a Spectacular 404 Error Page (with 12 Examples)
3 methods to create a customized error 404 page · 1. Use 404 Page WordPress Plugin – You are lucky if you run...
Read more >Error 404 not found - What does it mean & how to fix it! - IONOS
Reload the page: It might be that the error 404 has appeared for the simple reason that the page did not load properly....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What is your concrete use case?
You can already hack something like this today.
Yea I was thinking about something like this as well.
I still struggle to see a use case for this. But I’m happy to be shown wrong and more than happy to re-open this.