Skip to content

Instantly share code, notes, and snippets.

@gegeke
Created April 20, 2021 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gegeke/0a1092a402231305e258d9ca277b3890 to your computer and use it in GitHub Desktop.
Save gegeke/0a1092a402231305e258d9ca277b3890 to your computer and use it in GitHub Desktop.
Creating an API HUB 05
// unification of return values - even more sensible!
const fetchAPI = async ({ url = null } = { url: null }) => {
if (url) {
try {
const response = await fetch(url)
if (!response.ok) {
throw {
isError: true,
data: [],
}
}
const json = await response.json()
return {
isError: false,
data: json,
}
} catch (err) {
throw err
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment