Skip to content

Commit

Permalink
the fetch api is different than axios - errors appear in the data obj…
Browse files Browse the repository at this point in the history
…ect - handle that
  • Loading branch information
idanlo committed Jun 9, 2019
1 parent 367dbe6 commit cfc85f4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/ApiRequest/useApiRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ function useApiRequest(url, options = {}) {
}
});
const data = await res.json();
setData(data);
setLoading(false);
if (data.error) {
setError(true);
} else {
setData(data);
}
} catch (e) {
setLoading(false);
setError(true);
Expand Down

0 comments on commit cfc85f4

Please sign in to comment.