Throw on CryptoCompare API error (#486)

* Throw properly on API error.
This commit is contained in:
William O'Beirne 2017-11-29 11:45:38 -08:00 committed by Daniel Ternyak
parent 51db31b9fa
commit 5b07395ee4
1 changed files with 5 additions and 0 deletions

View File

@ -26,6 +26,11 @@ export const fetchRates = (symbols: string[] = []): Promise<CCResponse> =>
fetch(CCRates(symbols))
.then(response => handleJSONResponse(response, ERROR_MESSAGE))
.then(rates => {
// API errors come as 200s, so check the json for error
if (rates.Response && rates.Response === 'Error') {
throw new Error('Failed to fetch rates');
}
// All currencies are in ETH right now. We'll do token -> eth -> value to
// do it all in one request
// to their respective rates via ETH.