Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active April 2, 2019 18:06
Show Gist options
  • Save gladchinda/99973de7e28e7f8e7a9d87edecebf4e1 to your computer and use it in GitHub Desktop.
Save gladchinda/99973de7e28e7f8e7a9d87edecebf4e1 to your computer and use it in GitHub Desktop.
const exchangeRate = currency => {
const symbol = `${BASE_CURRENCY}_${currency}`;
return fetch(`${API_URL}&q=${symbol}`)
.then(response => response.json())
.then(data => [ currency, data[symbol] || null ])
// Attach a `.catch()` handler for graceful rejection handling
.catch(() => [ currency, null ]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment