From a4f19380ff7ab865028eb6666072ae2f31ed021e Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 27 Jun 2023 17:15:07 +0200 Subject: [PATCH] Handle error in GetGeoLocationByName Return error when fetching GeoLocations fails or the result is empty. This ensures that an error is properly returned and handled when either an error occurs during the API call or no locations are found for the given city name. --- geolocation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geolocation.go b/geolocation.go index 08a6abc..632da79 100644 --- a/geolocation.go +++ b/geolocation.go @@ -43,7 +43,7 @@ type GeoLocation struct { // This method makes use of the OSM Nominatim API func (c *Client) GetGeoLocationByName(ci string) (GeoLocation, error) { ga, err := c.GetGeoLocationsByName(ci) - if len(ga) < 1 { + if err != nil || len(ga) < 1 { return GeoLocation{}, err } return ga[0], nil