From b824f67a9a7095856b9965817f767d1101274396 Mon Sep 17 00:00:00 2001 From: txlyre Date: Mon, 29 Mar 2021 00:29:46 +0300 Subject: [PATCH] Handle VK API errors properly. --- automaton.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/automaton.py b/automaton.py index 04c4239..49f7b57 100644 --- a/automaton.py +++ b/automaton.py @@ -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) @@ -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)