devvmh/redux-crud-store

http response error not handled

julienR2 opened this issue · 2 comments

Hi !

Diving more into the lib I started to use the apiCall for non-rest endpoints (in my case to handle authentication). First thanks for this function, it allows me to use the lib more globally for almost all my request so far.

Only thing about this apiCall (and I suspect from the other call function), they don't handle http error. In case I receive a 400/403/404/500, the success event is triggered anyway. Diving into the code it seems it is because the apiGeneric function set up a try catch, but doesn't check the status of the response.

Is it wanted ? Why not add a check and trigger a real success event in case their is no error And the http response is <400 ?

I'll fork it and try it too :) Maybe I'll answer myself later !

Thanks in advance for any information !

Resources for good error handling with fetch https://www.tjvantoll.com/2015/09/13/fetch-and-errors/

This article send back a response.statusText, however I would throw a response.json() error anyway (in case of 400, 404, or 403) counting with the fact that the rest api should give use back a json formatted error.

#42 looks great, see my comments there! Thanks!