T
TanStack13mo ago
deep-jade

Handling Errors in NextJS & React 18 >

Guys, as we know in react 18> the errors thrown with 'throw new Error()' are omitted in production because of security measurements (check this link - https://joulev.dev/blogs/throwing-expected-errors-in-react-server-actions). I might be wrong but I was just wondering how would we go about executing onError callback with a particular error object that comes from a 3rd party API. E.x looking at the server action in the photo and based on the solution from the link above, I am able to use throw new ActionError which makes react to not omit it in production, but the thing is that onError callback won't get triggered in this case because we are just returning the object in the client side. I am assuming this doesn't have any solution and the way to go is whenever we want to add toaster when an error like "invalid credentials" happens we should do it in the onSuccess callback and check the data if error exists. Maybe it's just me misunderstanding the onError callback (maybe I should use it only for general errors with the server that I could just add a toaster with a default message "Something went wrong, try again later").
No description
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?