4

https://nextjs.org/docs/app/building-your-application/routing/error-handling#handling-server-errors

Above doc link tells

If an error is thrown inside a Server Component, Next.js will forward an Error object (stripped of sensitive error information in production) to the nearest error.js file as the error prop. During production, the Error object forwarded to the client only includes a generic message and digest property. This is a security precaution to avoid leaking potentially sensitive details included in the error to the client. The message property contains a generic message about the error and the digest property contains an automatically generated hash of the error that can be used to match the corresponding error in server-side logs. During development, the Error object forwarded to the client will be serialized and include the message of the original error for easier debugging.

In my app, i have controlled errors and i want to display those messages to user for some clarity, is there a way I configure nextjs to pass me actual error message to be displayed on error page and skip stripping of error message?

3
  • did you ever find a sensible solution for not having these errors "censored"? Commented Jun 26, 2024 at 14:55
  • did you ever find a sensible solution for not having these errors "censored"? Commented Jun 30, 2024 at 16:15
  • The documentation link from nextjs has removed this mention. but this "feature" is still present Commented Nov 16, 2024 at 15:33

1 Answer 1

0

I recommend you catch them through error handling and then save them into a file by utilizing the winston library. After all, you can show preferred logs by adding a new page and searching in your saved logs. Here you can find a good article to save your logs:

https://dev.to/abhijitdotsharma/production-essentials-logging-in-nextjs-13-43l0

Here you can find the full document about winston and how to search in your saved logs to display as needed:

https://github.com/winstonjs/winston?tab=readme-ov-file#querying-logs

Sign up to request clarification or add additional context in comments.

1 Comment

That's a horrible suggestion. That would require wrapping all server code in a try/catch block. There must be a better way. For instance, Next does generate a unique Digest code for each error. The code would be useless if there were no way to use it to look up the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.