Integrating Effect with tRPC: Handling and Mapping Errors

I'm incrementally adopting Effect in an existing tRPC API. Right now all the business logic is Effectful code, and the tRPC procedures run the effects with a ManagedRuntime

My question is if folks have done something similar and if so, how do you handle returning results back over the wire? My strategy has been to catch various tagged errors and map them back to TRPCError instances, then re-throwing them to the client (with the tagged error being the original cause). Is this a valid approach, or is there a smarter integration I can use with react-query and tRPC to have more type-safe errors on the frontend (e.g. with runPromiseExit or Either types)?

Here's an example illustrating what I'm talking about https://effect.website/play#5e3b33d7c379
Was this page helpful?