Skip to content

Instantly share code, notes, and snippets.

@adeleke5140
Created October 11, 2022 01:10
Show Gist options
  • Select an option

  • Save adeleke5140/f801ebeca1f8298c24e8c7285ab9e351 to your computer and use it in GitHub Desktop.

Select an option

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