Skip to content

Commit 6d96f7e

Browse files
authored
fix: capture and nicely handle request timeouts (#773)
1 parent e6397eb commit 6d96f7e

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

mapillary_tools/authenticate.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,28 @@ def fetch_user_items(
127127

128128
assert profile_name is not None, "profile_name should be set"
129129

130-
user_items = _verify_user_auth(_validate_profile(user_items))
131-
132-
LOG.info(
133-
f'Uploading to profile "{profile_name}": {user_items.get("MAPSettingsUsername")} (ID: {user_items.get("MAPSettingsUserKey")})'
134-
)
130+
try:
131+
LOG.info(f'Verifying profile "{profile_name}"...')
132+
user_items = _verify_user_auth(_validate_profile(user_items))
135133

136-
if organization_key is not None:
137-
with api_v4.create_user_session(user_items["user_upload_token"]) as session:
138-
resp = api_v4.fetch_organization(session, organization_key)
139-
data = api_v4.jsonify_response(resp)
140134
LOG.info(
141-
f"Uploading to organization: {data.get('name')} (ID: {data.get('id')})"
135+
f'Uploading to profile "{profile_name}": {user_items.get("MAPSettingsUsername")} (ID: {user_items.get("MAPSettingsUserKey")})'
142136
)
143-
user_items["MAPOrganizationKey"] = data.get("id")
137+
138+
if organization_key is not None:
139+
with api_v4.create_user_session(user_items["user_upload_token"]) as session:
140+
resp = api_v4.fetch_organization(session, organization_key)
141+
data = api_v4.jsonify_response(resp)
142+
LOG.info(
143+
f"Uploading to organization: {data.get('name')} (ID: {data.get('id')})"
144+
)
145+
user_items["MAPOrganizationKey"] = data.get("id")
146+
147+
except requests.Timeout as ex:
148+
raise exceptions.MapillaryUploadTimeoutError(str(ex)) from ex
149+
150+
except requests.ConnectionError as ex:
151+
raise exceptions.MapillaryUploadConnectionError(str(ex)) from ex
144152

145153
return user_items
146154

0 commit comments

Comments
 (0)