zooniverse / json-api-client

Apache License 2.0
10 stars 5 forks source link

Promises get rejected on any error, rather than network errors only #27

Open rogerhutchings opened 8 years ago

rogerhutchings commented 8 years ago

https://github.com/zooniverse/json-api-client/blob/df87d8a3ed1afa007aa2a9a4246901111f5adae4/src/make-http-request.coffee#L39-L40

We shouldn't be rejecting promises just because there's an error; that should be reserved for instances where we're unable to get a response from the server at all. This is (I suspect) the cause of zooniverse/panoptes-javascript-client#25

cc @eatyourgreens

eatyourgreens commented 8 years ago

Jake Archibald suggests a workaround here: https://www.tjvantoll.com/2015/09/13/fetch-and-errors/#comment-2254532318

Promise rejections are for errors (they're analogous to the catch in try-catch), so we'd need to define some kind of ResponseError, which is like an error in terms of stack traces, but is otherwise the same as a Response.

Then, in the catch/reject you'll have to type check a TypeError (generated by a network failure) from a ResponseError (generated by a successful response with particular status codes).

There isn't really anything else in the web platform that behaves like this.

At the moment, there's no way for client code to intelligently handle HTTP errors, as referenced in zooniverse/panoptes-javascript-client#25