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.
This commit is contained in:
Winni Neessen 2023-06-27 17:15:07 +02:00
parent d0905266e1
commit a4f19380ff
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -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