Next.js Discord

Discord Forum

How can I handle errors in `error.ts` without changing the UI?

Answered
effeKtSVK posted this in #help-forum
Open in Discord
Avatar
Hi, I would like to ask if it is possible to catch all errors but without replacing the UI.

I'm using App Router and I tried to implement custom error boundary with getDerivedStateFromError which didn't work and I found out that I need to use error.ts file.

The thing is that I just want to keep displaying the original children and only show a toast for the caught errors. Is there a way to do it since the children are not available in the props of the error.ts component?
Answered by effeKtSVK
Okay, I found out that the error boundary only catches errors during the rendering phase, my bad. That means the children are undefined, that's why the fallback is basically necessary. So other than that, the custom error boundary works fine!
View full answer

1 Reply

Avatar
Okay, I found out that the error boundary only catches errors during the rendering phase, my bad. That means the children are undefined, that's why the fallback is basically necessary. So other than that, the custom error boundary works fine!
Answer