Skip to content

Instantly share code, notes, and snippets.

@adeleke5140
Created October 11, 2022 01:10
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 adeleke5140/f801ebeca1f8298c24e8c7285ab9e351 to your computer and use it in GitHub Desktop.
Save adeleke5140/f801ebeca1f8298c24e8c7285ab9e351 to your computer and use it in GitHub Desktop.
fetching data asynchronously with error catching
const data = [];
const error = null;
const load = async () => {
try{
let response = await fetch('')
if(!data.ok){
throw Error('error message')
}
data = await response.json()
}
catch(err){
error = err.message
console.log(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment