next-learn icon indicating copy to clipboard operation
next-learn copied to clipboard

chapter 13, handling 404 errors does not work

Open sturmf opened this issue 1 year ago • 2 comments

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.

sturmf avatar Jan 06 '24 15:01 sturmf

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.

delbaoliveira avatar Jan 08 '24 12:01 delbaoliveira

I have the same issue using vercel/postgres. Like @sturmf stated, commenting out line 174 from data.ts will return the custom 404 page.

doolaik avatar Mar 05 '24 18:03 doolaik

I am not able to reproduce this. Please open a new issue if you are still having trouble here. Thank you!

leerob avatar Jun 23 '24 22:06 leerob