From fb158d4767b85160c0c2c5fea5c6429c265576a9 Mon Sep 17 00:00:00 2001 From: Dick Wolff Date: Wed, 13 Jan 2021 22:19:17 +0100 Subject: Error handling and fixed link to city. --- src/components/services/OpenWeather.vue | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue index c535a89..8029716 100644 --- a/src/components/services/OpenWeather.vue +++ b/src/components/services/OpenWeather.vue @@ -1,7 +1,7 @@

@@ -49,7 +54,9 @@ export default { item: Object, }, data: () => ({ + error: false, api: { + id: "", name: "", weather: [ { @@ -65,8 +72,14 @@ export default { }, }), computed: { - temp: function () { + locationId: function () { if (this.api) { + return this.api.id; + } + return ""; + }, + temp: function () { + if (this.api && this.api.main.temp !== "") { return parseInt(this.api.main.temp).toFixed(1); } return ""; @@ -92,13 +105,19 @@ export default { const url = `https://api.openweathermap.org/data/2.5/weather?q=${this.item.location}&appid=${this.item.apiKey}&units=${this.item.units}`; this.api = await fetch(url) .then((response) => response.json()) - .catch((e) => console.log(e)); + .catch((e) => { + this.error = true; + console.log(e) + }); }, }, };