Next.js Discord

Discord Forum

Preventing message omitting in Error Boundaries

Answered
Pine Bunting posted this in #help-forum
Open in Discord
Pine BuntingOP
Is it possible to disable "The specific message is omitted in production builds to avoid leaking sensitive details." feature for certain errors in Error boundaries? are Error boundaries just for dev-related errors?

https://nextjs.org/docs/app/building-your-application/routing/error-handling#securing-sensitive-error-information
Answered by joulev
Error boundaries are meant for unexpected errors. Expected errors (eg user is not authenticated) should be handled separately with, say, if/else statements or redirect()/notFound().

Unexpected errors on the clients are preserved as-is when going to the error boundary.

Unexpected errors on the server typically have sensitive information. Hence it’s a security feature that such information is omitted when sending to the client and it cannot be turned off. You can always use the digest to check the server log and figure out the full error message
View full answer

2 Replies

@Pine Bunting Is it possible to disable "The specific message is omitted in production builds to avoid leaking sensitive details." feature for certain errors in Error boundaries? are Error boundaries just for dev-related errors? https://nextjs.org/docs/app/building-your-application/routing/error-handling#securing-sensitive-error-information
Error boundaries are meant for unexpected errors. Expected errors (eg user is not authenticated) should be handled separately with, say, if/else statements or redirect()/notFound().

Unexpected errors on the clients are preserved as-is when going to the error boundary.

Unexpected errors on the server typically have sensitive information. Hence it’s a security feature that such information is omitted when sending to the client and it cannot be turned off. You can always use the digest to check the server log and figure out the full error message
Answer
This is insanely inconvenient approach that breaks React/Next own philosophy of fetching data closer to the components.

If some component deep down the tree throws an error that a user is not unauthenticated, I have no way to intercept it, even if i want to.

*Sorry for the necro lol i got a bit emotional