T
TanStack7mo ago
sensitive-blue

Global Error handler in start?

I have an issue where I am throwing errors from some server functions but when I try to catch them in the client I don't have a good way to actually identify if the error is okay to display to the user because I threw it or if its caused by something I don't want to expose. Generally in an API you would have a custom error class and a global error handler that catches all errors and returns a generic error for all errors that are not instances of your custom error class. Is there a way to do something similar in Start? Or can I solve this issue a different way? To be as clear as possible what I want is to be able to send errors from my server functions and have the client display them. But I want to send/display a generic error for anything unexpected and send/display more informative errors otherwise
6 Replies
broad-brown
broad-brown7mo ago
so some kind of error interception we don't have that yet but could be added
sensitive-blue
sensitive-blueOP7mo ago
Is there a hack I can do in the mean time? Because if I try to make a custom error class and throw that it will be serialized and I'll get a normal error in the frontend
broad-brown
broad-brown7mo ago
normal error?
sensitive-blue
sensitive-blueOP7mo ago
Well I mean that it won't be my custom class so I can't check in the frontend that it is my custom class then show that error otherwise show generic error
broad-brown
broad-brown7mo ago
ah yeah cause the instance information is lost
sensitive-blue
sensitive-blueOP7mo ago
The only idea I have is to prefix the message with some string to identify it. But seems error prone

Did you find this page helpful?