Skip to content

Commit

Permalink
fix wwo panic on geo failure
Browse files Browse the repository at this point in the history
  • Loading branch information
schachmat committed May 5, 2016
1 parent 1b912a3 commit 63a126f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backends/worldweatheronline.com.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,19 @@ func (c *wwoConfig) getCoordinatesFromAPI(queryParams []string, res chan *iface.
if err != nil {
log.Println("Unable to fetch geo location:", err)
res <- nil
return
} else if hres.StatusCode != 200 {
log.Println("Unable to fetch geo location: http status", hres.StatusCode)
res <- nil
return
}
defer hres.Body.Close()

body, err := ioutil.ReadAll(hres.Body)
if err != nil {
log.Println("Unable to read geo location data:", err)
res <- nil
return
}

if c.debug {
Expand All @@ -285,12 +288,14 @@ func (c *wwoConfig) getCoordinatesFromAPI(queryParams []string, res chan *iface.
if err = json.Unmarshal(body, &coordResp); err != nil {
log.Println("Unable to unmarshal geo location data:", err)
res <- nil
return
}

r := coordResp.Search.Result
if len(r) < 1 || r[0].Latitude == nil || r[0].Longitude == nil {
log.Println("Malformed geo location response")
res <- nil
return
}

res <- &iface.LatLon{Latitude: *r[0].Latitude, Longitude: *r[0].Longitude}
Expand Down

0 comments on commit 63a126f

Please sign in to comment.