Handling Client-Server Boundaries with Effect.ts and Error Serialization
I'm trying my hands with Effect.ts again but considering everything I've written so far is normal TypeScript, I feel I have trouble with the client and server boundaries. I use TanStack Start as a full-stack framework to handle both frontend and backend. Let's say I have a route where I request some user data from a database. Four things can happen:
- User has no session
- User has session but user is deleted
- Database query failed
- Database was queried successfully
Initially I would define
but I'm not sure due to the client/server communication, if I'm better off using
I either get the query from database or I throw relevant redirect/error depending on tag. In the loader then I have happy path only
Apologize it's a vague question, it's because I have trouble understanding the pattern
- User has no session
- User has session but user is deleted
- Database query failed
- Database was queried successfully
Initially I would define
but I'm not sure due to the client/server communication, if I'm better off using
Schema.TaggedError instead. Basically what I want from Effect is just the either, but since errors are classes, I run into serialization issues. So what I try is thisI either get the query from database or I throw relevant redirect/error depending on tag. In the loader then I have happy path only
Apologize it's a vague question, it's because I have trouble understanding the pattern
