Skip to content

Commit

Permalink
fix: add safety check for empty weather data response in FetchWeather…
Browse files Browse the repository at this point in the history
… method

- Implemented a safety check to handle cases where no weather conditions are returned from the OpenWeather API, preventing potential nil pointer dereferences and improving error handling.
  • Loading branch information
tphakala committed Jan 5, 2025
1 parent b26d1e5 commit 76b91cf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/weather/provider_openweather.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func (p *OpenWeatherProvider) FetchWeather(settings *conf.Settings) (*WeatherDat
break
}

// Safety check for weather data
if len(weatherData.Weather) == 0 {
return nil, fmt.Errorf("no weather conditions returned from API")
}

return &WeatherData{
Time: time.Unix(weatherData.Dt, 0),
Location: Location{
Expand Down

0 comments on commit 76b91cf

Please sign in to comment.