Skip to content

Instantly share code, notes, and snippets.

@gegeke
Created April 20, 2021 18:41
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/eb50a9daaff659c9f3b2fa27a8d17636 to your computer and use it in GitHub Desktop.
Save gegeke/eb50a9daaff659c9f3b2fa27a8d17636 to your computer and use it in GitHub Desktop.
Creating an API HUB 02
// setting the params & defaulting it to null
const fetchAPI = async ({ url = null } = { url: null }) => {
if (url) {
// handling error cases with a try-catch
try {
const response = await fetch(url)
return response
} catch (err) {
console.error(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment