Next.js Discord

Discord Forum

Throw Custom Error

Answered
Yves posted this in #help-forum
Open in Discord
I throw a custom error with the intention of it reaching the error.tsx file so that I can display the error keys, however, even instantiating the object in the correct way, the keys arrive as undefined in the error.tsx file, why?
Answered by LuisLl
If you’re throwing the error from the Server you can’t get the data to show on the error boundary because Next.js prevents sensitive information from being leaked.

If you were throwing the error in a client component you’d get the information instead of the digest property.
View full answer

11 Replies

Are you running the app in dev mode?

Also, the modal that appears when you trigger the error, is that the UI from error.tsx or what is it?
yes, Im executing in dev mode

yes, the modal is from error.tsx
sorry for the late in answer
I managed to display the operationId, but I needed to overwrite the 'digest' property which is native to the 'Error' of next, but if I try to create another class based on the Error Class, this property is not recognized.
If you’re throwing the error from the Server you can’t get the data to show on the error boundary because Next.js prevents sensitive information from being leaked.

If you were throwing the error in a client component you’d get the information instead of the digest property.
Answer
Got it, now it makes sense, thanks a lot again Luis
Of course, happy to help. Look at the docs here for further clarification
https://nextjs.org/docs/app/api-reference/file-conventions/error#reference
I missed this "good to know"
:/
@Yves I missed this "good to know"
Don’t worry, now you know never to skip those because are definitely good to know 😂