1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Don't panic when there's no city data for Weather

This commit is contained in:
Chris Cummer 2019-05-15 18:31:59 -07:00
parent 405beea6d3
commit accfa70ba5

View File

@ -9,24 +9,27 @@ import (
)
func (widget *Widget) display() {
err := ""
var err string
if widget.apiKeyValid() == false {
err += " Environment variable WTF_OWM_API_KEY is not set\n"
err = " Environment variable WTF_OWM_API_KEY is not set\n"
}
cityData := widget.currentData()
if cityData == nil {
if err == "" && cityData == nil {
err += " Weather data is unavailable: no city data\n"
}
if len(cityData.Weather) == 0 {
err += " Weather data is unavailable: no weather data"
if err == "" && len(cityData.Weather) == 0 {
err += " Weather data is unavailable: no weather data\n"
}
title := widget.CommonSettings.Title
setWrap := false
var content string
if err != "" {
setWrap = true
content = err
} else {
title = widget.buildTitle(cityData)
@ -37,7 +40,7 @@ func (widget *Widget) display() {
content = content + widget.sunInfo(cityData)
}
widget.Redraw(title, content, false)
widget.Redraw(title, content, setWrap)
}
func (widget *Widget) description(cityData *owm.CurrentWeatherData) string {