Skip to content

Commit

Permalink
Improve location error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
l0drex committed Jan 16, 2024
1 parent 94bfeb9 commit 2c854be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion yin_yang/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def defaults(self) -> dict:
'running': False,
'dark_mode': False,
'mode': Modes.MANUAL.value,
'coordinates': (0, 0),
'coordinates': (0.0, 0.0),
'update_location': False,
'update_interval': 60,
'times': ('07:00', '20:00'),
Expand Down
9 changes: 7 additions & 2 deletions yin_yang/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ def get_qt_position() -> QGeoCoordinate:

def get_ipinfo_position() -> QGeoCoordinate:
# use the old method as a fallback
response = requests.get('https://www.ipinfo.io/loc')
try:
response = requests.get('https://www.ipinfo.io/loc')
except Exception as e:
logger.error(e)
raise TypeError('Error while sending a request to get location')

if not response.ok:
logger.error('Failed to get location from ipinfo.io')
raise TypeError('Failed to get location from ipinfo.io')

loc_response = response.text.removesuffix('\n').split(',')
loc: [float] = [float(coordinate) for coordinate in loc_response]
Expand Down

0 comments on commit 2c854be

Please sign in to comment.