diff --git a/util/getWeather.js b/util/getWeather.js index cce7049..a774c9b 100644 --- a/util/getWeather.js +++ b/util/getWeather.js @@ -1,10 +1,17 @@ const https = require('https'); module.exports = async function (location) { + const options = { + hostname: "wttr.in", + port: 443, + path: `${location}?format=4&M`, + method: 'GET', + timeout: 5000 + } const url = `https://wttr.in/${location}?format=4&M` // 4 = one line, M = metric wind speed let success = false; let weather = await new Promise((resolve, reject) => { - https.get(url, (res) => { + https.get(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; @@ -24,7 +31,10 @@ module.exports = async function (location) { }); }).on("error", (err) => { reject(err); + }).on('timeout', (err) => { + reject(err) }); + }) return {success: success, weather: weather};