Skip to content

Instantly share code, notes, and snippets.

@samuraijane
Last active July 5, 2022 07:17
Show Gist options
  • Save samuraijane/4529180fb3f885d9246f0c7b4f2cc769 to your computer and use it in GitHub Desktop.
Save samuraijane/4529180fb3f885d9246f0c7b4f2cc769 to your computer and use it in GitHub Desktop.
const shoppingList = ['apples', 'biscuits', 'cabbage', 'dip'];
const isCode200 = () => Math.random() >= 0.5;
function getShoppingList() {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (isCode200()) {
resolve(shoppingList);
} else {
reject('There was a problem with the server, please try again.');
}
}, 500);
});
}
getShoppingList()
.then(data => console.log(data))
.catch(err => console.error(`ERR: ${err}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment