How to handle throw error on server component?
Unanswered
American black bear posted this in #help-forum
American black bearOP
On production build, error.tsx has no original error information, just
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.
but i need the original message for handling it, such as Unauthorized, forbidden, etc
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.
but i need the original message for handling it, such as Unauthorized, forbidden, etc
3 Replies
American black bearOP
i calling trpc on server component
@American black bear On production build, error.tsx has no original error information, just
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.
but i need the original message for handling it, such as Unauthorized, forbidden, etc
errors can contain sesitive information. Because of that they are visible in development but not in production. You can take a look at this guide on what you need to change to display the actual error: https://joulev.dev/blogs/throwing-expected-errors-in-react-server-actions
TL;DR
Build a proper error handling system or use an existing one. I like to use https://next-safe-action.dev/
This example guides are for server actions. You can use the same system for serverside errors
TL;DR
Build a proper error handling system or use an existing one. I like to use https://next-safe-action.dev/
This example guides are for server actions. You can use the same system for serverside errors
@American black bear solved?