diff --git a/index.js b/index.js index fdb3ad5..2b5f646 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,12 @@ const baseUrl = 'https://min-api.cryptocompare.com/data/' function fetchJSON (url) { return fetch(url) - .then(res => res.json()) + .then(res => { + if (!res.ok) { + throw new Error(`${res.status} ${res.statusText}`) + } + return res.json() + }) .then(body => { if (body.Response === 'Error') throw body.Message return body