From d8649ff943fa4b87b3ebeefc2aff1835a38699f3 Mon Sep 17 00:00:00 2001
From: SileNce5k <ozzynexus@gmail.com>
Date: Mon, 4 Dec 2023 15:47:07 +0100
Subject: [PATCH] Fix crash on weather command with invalid location

---
 commands/misc/weather.js | 5 ++++-
 util/getWeather.js       | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/commands/misc/weather.js b/commands/misc/weather.js
index 1b4de57..8f8bd76 100644
--- a/commands/misc/weather.js
+++ b/commands/misc/weather.js
@@ -9,8 +9,11 @@ module.exports = {
 			return;
 		}
 		let location = args.join(" ")
-		let weather = await getWeather(location).catch((err) => {
+		let weather = {};
+		weather = await getWeather(location).catch((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
diff --git a/util/getWeather.js b/util/getWeather.js
index e41b396..34208e1 100644
--- a/util/getWeather.js
+++ b/util/getWeather.js
@@ -11,10 +11,10 @@ module.exports = async function (location) {
 			});
 			res.on('end', () => {
 				if(res.statusCode === 404){
-					reject(`Couldn't find weather for ${location}`);
+					resolve(`Couldn't find weather for ${location}`);
 					return;
 				}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{
 					resolve(data);
 					success = true;