Utilize error.ts in prod
Unanswered
Lilac posted this in #help-forum
LilacOP
In dev, simply throwing errors like
In production, the message is replaced with
How do I implement the same dev behavior in prod?
throw new Error("Message") shows the user the error.ts fallback ui with the defined message.In production, the message is replaced with
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.How do I implement the same dev behavior in prod?
8 Replies
Errors forwarded from Server Components show a generic message with an identifier. This is to prevent leaking sensitive details. You can use the identifier, under errors.digest, to match the corresponding server-side logs.LilacOP
I understand, but is there a way to achieve a similar behavior in prod?
For example if
Will I have to handle 403 erorr in every page and return something?
For example if
res.status == 403 I would return the Error file with "You dont have permissions to access this page" message in prod. If throwing error wont work, what is the alternative?Will I have to handle 403 erorr in every page and return something?
@Lilac I understand, but is there a way to achieve a similar behavior in prod?
For example if res.status == 403 I would return the Error file with "You dont have permissions to access this page" message in prod. If throwing error wont work, what is the alternative?
Will I have to handle 403 erorr in every page and return something?
There is no way to achieve this behavior using the
error.js file afaik, this is because error.js is for unexpected errors, what you are describing is an expected error that you need to handle on your own.@Plague There is no way to achieve this behavior using the `error.js` file afaik, this is because `error.js` is for unexpected errors, what you are describing is an expected error that you need to handle on your own.
LilacOP
Would have been nice if it worked in prod too, in some way.
@Lilac Would have been nice if it worked in prod too, in some way.
Too risky, can't leak sensitive data. Just handle the error yourself by creating an error component that renders on the page when the user doesn't have access with a button to return to a non-protected route or something similar depending on your use case
No problem