Created
October 11, 2022 01:10
-
-
Save adeleke5140/f801ebeca1f8298c24e8c7285ab9e351 to your computer and use it in GitHub Desktop.
fetching data asynchronously with error catching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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