Accessing the actual error in global-error
Answered
Nile Crocodile posted this in #help-forum
Nile CrocodileOP
Hi, I am wondering how to access the actual error inside a global error page. I am always getting a censored error. Help
Answered by joulev
global-error.js and error.js are meant for unexpected errors (i.e. bugs in your code and the app has crashed). hence the error is censored.
for expected errors (e.g. user errors), simply use conditional statements inside the page to render the error message
for expected errors (e.g. user errors), simply use conditional statements inside the page to render the error message
5 Replies
@Nile Crocodile Hi, I am wondering how to access the actual error inside a global error page. I am always getting a censored error. Help
global-error.js and error.js are meant for unexpected errors (i.e. bugs in your code and the app has crashed). hence the error is censored.
for expected errors (e.g. user errors), simply use conditional statements inside the page to render the error message
for expected errors (e.g. user errors), simply use conditional statements inside the page to render the error message
Answer
@joulev global-error.js and error.js are meant for unexpected errors (i.e. bugs in your code and the app has crashed). hence the error is censored.
for expected errors (e.g. user errors), simply use conditional statements inside the page to render the error message
Nile CrocodileOP
Isn't there are more generic way of handling errors? I thought about declaring an error class and catch it globally (e.g. for site permissions, thrown by actions)
@Nile Crocodile Isn't there are more generic way of handling errors? I thought about declaring an error class and catch it globally (e.g. for site permissions, thrown by actions)
anything thrown inside actions and server components are censored, so no.
technically, the
of course keep in mind you have
if
statement is the way.technically, the
digest
property of the error (if any) is not censored, so there is that. then you can make your own notFound
and not-found.js
by making a function that throws a custom error with a custom digest – refer to the notFound
implementation for more details. this is far from easy though, i dont see how the benefit outweighs the amount of effort required here.of course keep in mind you have
notFound
, forbidden
, unauthorized
that you can use here without having to make your own.Nile CrocodileOP
Interesting, thanks! Do you have a good example for
forbidden
and unauthorized
? Couldn't find any