sukovanej / effect-http

Declarative HTTP API library for effect-ts
https://sukovanej.github.io/effect-http
MIT License
248 stars 20 forks source link

Feature Request: Client should return all expected status codes #533

Open TylorS opened 5 months ago

TylorS commented 5 months ago

At present a Client derived from an API loses all type-safety in regards to any non-2xx status codes which are returned directly when making use of the Client's methods.

The way to recover access errors are via ClientError. The server-side ClientError's, which do have a status, are typed as unknown 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

sukovanej commented 5 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

adrian-gierakowski commented 2 months ago

@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).

danielo515 commented 1 month ago

I am also interested in graceful handling of errors. If I hate something is libraries that throw in non 2xx scenarios