aboutsummaryrefslogtreecommitdiffstats
path: root/fnme/geo.py
diff options
context:
space:
mode:
authorAlex Schofield <git@ajschof.me>2026-05-05 22:07:44 +0100
committerAlex Schofield <git@ajschof.me>2026-05-05 22:07:44 +0100
commit736e7dabf47b7de949c55907d2d238f954a4c29e (patch)
tree8dd04a95335fdbf2f65d9596b5e664934ad71d24 /fnme/geo.py
parentc247d6e6fddb91a43b99758711912e8a6ed3e97c (diff)
downloadfuelnearme-736e7dabf47b7de949c55907d2d238f954a4c29e.tar.gz
fuelnearme-736e7dabf47b7de949c55907d2d238f954a4c29e.zip
improve error handling during geolocation
Diffstat (limited to 'fnme/geo.py')
-rw-r--r--fnme/geo.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/fnme/geo.py b/fnme/geo.py
index dba68fe..ec10237 100644
--- a/fnme/geo.py
+++ b/fnme/geo.py
@@ -1,10 +1,18 @@
+from geopy import exc
from geopy.geocoders import Nominatim
from geopy.location import Location
+from fnme.exceptions import LocationError
+
def get_location(address: str) -> tuple[float, float]:
geolocator = Nominatim(user_agent="FuelNearMe")
- result = geolocator.geocode(address)
+
+ try:
+ result = geolocator.geocode(address)
+ except exc.GeopyError as e:
+ raise LocationError(message=f"Location service error: {e}")
+
if not isinstance(result, Location):
- raise ValueError(f"Failed to get location from address: '{address}'")
+ raise LocationError(message=f"Unknown location: '{address}'")
return (result.latitude, result.longitude)
git.ajschof.me — hosted by ajschofield — powered by cgit