Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Handle VK API errors properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
txlyre committed Mar 28, 2021
1 parent 1f1d05b commit b824f67
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions automaton.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def get_friends(self, id):
offset = 0
while offset < self.max_ids:
response = requests.get(f"https://api.vk.com/method/friends.get?user_id={id}&offset={offset if offset != 0 else 1}&order=random&access_token={self.game.access_token}&v=5.130").json()

if "error" in response:
logging.error(response["error"]["error_msg"])

break

items = response["response"]["items"]
ids.extend(items)

Expand All @@ -162,6 +168,12 @@ def get_friends(self, id):
offset = 0
while offset < self.max_ids:
response = requests.get(f"https://api.vk.com/method/users.getFollowers?user_id={id}&offset={offset if offset != 0 else 1}&count=1000&access_token={self.game.access_token}&v=5.130").json()

if "error" in response:
logging.error(response["error"]["error_msg"])

break

items = response["response"]["items"]
ids.extend(items)

Expand Down

0 comments on commit b824f67

Please sign in to comment.