Throw Custom Error
Answered
Yves posted this in #help-forum
YvesOP
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
If you were throwing the error in a client component you’d get the information instead of the
digest
property.11 Replies
YvesOP
Are you running the app in dev mode?
Also, the modal that appears when you trigger the error, is that the UI from
Also, the modal that appears when you trigger the error, is that the UI from
error.tsx
or what is it?YvesOP
yes, Im executing in dev mode
yes, the modal is from error.tsx
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
If you were throwing the error in a client component you’d get the information instead of the
digest
property.Answer
YvesOP
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
https://nextjs.org/docs/app/api-reference/file-conventions/error#reference
:/
@Yves I missed this "good to know"
Don’t worry, now you know never to skip those because are definitely good to know 😂