Fix crash on weather command with invalid location

This commit is contained in:
SileNce5k 2023-12-04 15:47:07 +01:00
parent d1903c27e7
commit d8649ff943
No known key found for this signature in database
GPG key ID: 961132EB78C8915F
2 changed files with 6 additions and 3 deletions

View file

@ -9,8 +9,11 @@ module.exports = {
return; return;
} }
let location = args.join(" ") let location = args.join(" ")
let weather = await getWeather(location).catch((err) => { let weather = {};
weather = await getWeather(location).catch((err) => {
console.log(err); console.log(err);
weather.weather = `An error occured while getting the weather for ${location}\nSee console for more info`;
weather.success = false;
}); });
// convert °C to °F and add it after C temperature in parentheses // convert °C to °F and add it after C temperature in parentheses

View file

@ -11,10 +11,10 @@ module.exports = async function (location) {
}); });
res.on('end', () => { res.on('end', () => {
if(res.statusCode === 404){ if(res.statusCode === 404){
reject(`Couldn't find weather for ${location}`); resolve(`Couldn't find weather for ${location}`);
return; return;
}else if(res.statusCode != 200){ }else if(res.statusCode != 200){
reject(`Something went wrong while getting the weather for ${location}`); resolve(`Something went wrong while getting the weather for ${location}`);
} else{ } else{
resolve(data); resolve(data);
success = true; success = true;