Effect CommunityEC
Effect Community•2y ago•
5 replies
Kofi

Error Handling in `vite-remix-effect`

Hey! I was looking at the vite-remix-effect prototype and I noticed that the action/loaders do not return any errors instead prefering to throw them.
I'm guessing this is to follow the remix's idea of using error boundaries as much as possible, right?

Still I'm sure I'm not the only one that sometimes would prefer having typed errors over having to awkwardly narrow-check if the unknown error returned by useRouteError is of type X, Y, Z, right? 👀

So my question is... how'd you do it?

Would you folks think it would be a good idea to write something like useActionExit and useLoaderExit that will return a Promise<Exit<E, A>> over just Promise<A>?

Or would you just keep using useAction/loader but write your effect so that right at the very end you turn the success into an Either.right and catch some of the errors and turn them into an Effect.succeed(Either.left(__))?

I'm guessing the first option would be slightly easier to use but you then would end up not re-using the runtime as all your other calls that might use the non-exit versions of the loaders right?
While the later would ensure maximum reuse but imho would be fairly awkward to constantly elect stuff into eithers at the end of an effect
Was this page helpful?