next-learn
next-learn copied to clipboard
chapter 13, handling 404 errors does not work
In the example we get an error on a non existing invoice id in lib/data.ts on line 171
https://github.com/vercel/next-learn/blob/main/dashboard/final-example/app/lib/data.ts#L171
which is caught in line 172 and rethrown as a new Error.
In invoices/[id]/edit/page.tsx we are supposed to add
if (!invoice) {
notFound();
}
but this code is never reached. For me it only works if I uncomment the throw in data.ts.
// throw new Error('Failed to fetch invoice.');
Then the 404 logic kicks in and everything works as expected. Do only I have the problem? Btw. I changed the vercel/postgres to plain postgres.
Hey @sturmf 👋🏼
Since you're using your own postgres db, could you please check what value gets returned?
One explanation if the code is not reached is that invoice might be a truthy value.
I have the same issue using vercel/postgres. Like @sturmf stated, commenting out line 174 from data.ts will return the custom 404 page.
I am not able to reproduce this. Please open a new issue if you are still having trouble here. Thank you!