You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the code! I found that the getData function doesn't catch http.get errors, for instance when OpenWeatherMap is unreachable for whatever reason. To address this I edited the function as outlined below.
Thanks,
Regards, Anne
`function getData(url, callback, tries) {
options.path = url;
var DATA = http.get(options, (res) => {
var chunks = '';
res.on('data', (chunk) => {
chunks += chunk;
});
res.on('end', () => {
var parsed = {};
if (!chunks && (!tries || tries < 3)) {
return getData(url, callback, (tries || 0) + 1);
}
// Try-Catch added by Mikael Aspehed
try {
parsed = JSON.parse(chunks)
} catch (e) {
parsed = {
error: e
}
}
return callback(null, parsed);
});
res.on('error', (err) => {
console.log(`problem with request: ${err.message}`);
});
});
DATA.on('error', (err) => {
console.log(`problem with request: ${err.message}`);
});
};`
The text was updated successfully, but these errors were encountered:
Hi,
Thanks for the code! I found that the getData function doesn't catch http.get errors, for instance when OpenWeatherMap is unreachable for whatever reason. To address this I edited the function as outlined below.
Thanks,
Regards, Anne
The text was updated successfully, but these errors were encountered: