Browse Source

better error handling for exchange-rate api requests

fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
516c478937
  1. 7
      app.js

7
app.js

@ -54,7 +54,7 @@ app.use(express.static(path.join(__dirname, 'public')));
function refreshExchangeRate() { function refreshExchangeRate() {
if (coins[env.coin].exchangeRateData) { if (coins[env.coin].exchangeRateData) {
request(coins[env.coin].exchangeRateData.jsonUrl, function(error, response, body) { request(coins[env.coin].exchangeRateData.jsonUrl, function(error, response, body) {
if (!error && response.statusCode == 200) { if (!error && response && response.statusCode && response.statusCode == 200) {
var responseBody = JSON.parse(body); var responseBody = JSON.parse(body);
var exchangeRate = coins[env.coin].exchangeRateData.responseBodySelectorFunction(responseBody); var exchangeRate = coins[env.coin].exchangeRateData.responseBodySelectorFunction(responseBody);
@ -68,7 +68,10 @@ function refreshExchangeRate() {
console.log("Unable to get exchange rate data"); console.log("Unable to get exchange rate data");
} }
} else { } else {
console.log("Error " + response.statusCode) console.log("Error:");
console.log(error);
console.log("Response:");
console.log(response);
} }
}); });
} }

Loading…
Cancel
Save