Skip to content

Commit

Permalink
Merge pull request #5 from fac20/fetch-helper
Browse files Browse the repository at this point in the history
created fetchHelper to fishbase API
  • Loading branch information
fairyaksh authored Sep 16, 2020
2 parents 6c4e9ea + 294836c commit 6740ac7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/modules/fetch-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const API_BASE = "https://fishbase.ropensci.org/";

const fetchHelper = (url) => {
fetch(`${API_BASE}${url}`).then(checkResponse);
};

const checkResponse = (res) => {
if (!res.ok) {
throw new Error(`Error: ${res.status}`);
}
return res.json();
};

export { fetchHelper, checkResponse };

0 comments on commit 6740ac7

Please sign in to comment.