Does anyone have any recommendations for handling RPC response errors?
I want to do something like the
parseResult
function below so I can have consistent error handling across my app, but I've been struggling with getting type generics to work on the parseResult function such that the result type is correct.
I'm kind of curious if anyone has recommendations on how to best handle using the rpc client throughout the app, or maybe I'm just over complicating things.
3 Replies
what issue are you running into with the type generics?
the solution hinges a bit on how you want to use the resulting data, but something like this should work pretty well
So in your example you still need some type of type generic so that the result doesnt come back as any or unknown. I havent been able to get the result data to be typed properly from the rpc client.
Oh, I think I got it! I did some more research on how to add types to just a regular fetch, and found an example where they made a new type generic for the json/text functions themselves.
nice! seems legit