Skip to content

Commit f7ebd83

Browse files
committed
Catch redis errors, return err to user
1 parent 07efec7 commit f7ebd83

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

fingr/location.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import redis
99
import timezonefinder # type: ignore[import-untyped]
1010
from geopy.geocoders import Nominatim # type: ignore[import-untyped]
11-
from redis.exceptions import RedisError
11+
from redis.exceptions import ConnectionError, RedisError
1212

1313
from .logging import get_logger
1414
from .metrics import location_cache_operations, location_resolution_duration, track_time
@@ -48,9 +48,14 @@ def resolve_location(
4848
pass
4949

5050
# Check if in redis cache
51-
cache: Optional[bytes] = (
52-
redis_client.get(data) if redis_client is not None else None # type: ignore[assignment]
53-
)
51+
try:
52+
cache: Optional[bytes] = (
53+
redis_client.get(data) if redis_client is not None else None # type: ignore[assignment]
54+
)
55+
except (ConnectionError, RedisError) as err:
56+
logger.error("Redis connection error", err)
57+
return None, None, "Internal error", False
58+
5459
if cache:
5560
lat_str, lon_str, address = cache.decode("utf-8").split("|", 2)
5661
location_cache_operations.labels(operation="hit").inc()

0 commit comments

Comments
 (0)