Open TylorS opened 6 months ago
Hey, I agree the error responses are handled poorly right now. The most problematic traits I currently see:
I'll put there random thoughts and let's elaborate.
On the server side
On the client side
@TylorS @sukovanej have you given any further though to this or scheched something out privately? I'm using effect-http in production and not having typed error on the client side is a noticable downgrade compared api-ts (which we are still using on non-effect based projects).
I am also interested in graceful handling of errors. If I hate something is libraries that throw in non 2xx scenarios
At present a
Client
derived from anAPI
loses all type-safety in regards to any non-2xx status codes which are returned directly when making use of theClient
's methods.The way to recover access errors are via
ClientError
. The server-sideClientError
's, which do have a status, are typed asunknown
and must be re-validated manually to ensure type-safety on the client-side by hand.In an ideal world I think these would be strongly typed by default by using the "success" channel of Effect to return all "expected", as defined by your
API
, instead of only 2xx status codes. This allows for type-safe transformation of all "expected" status codes into domain-specific values and/or failures to correspond with these other expected conditions.Prior Discussion: https://github.com/sukovanej/effect-http/pull/515