Skip to content

Commit

Permalink
Update exception in VkTools.get_all_iter
Browse files Browse the repository at this point in the history
  • Loading branch information
python273 committed Apr 11, 2021
1 parent 571bb92 commit d49c1dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion vk_api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ class VkAudioUrlDecodeError(VkAudioException):


class VkToolsException(VkApiError):
pass
def __init__(self, *args, response=None):
super().__init__(*args)
self.response = response


class VkRequestsPoolException(Exception):
Expand Down
23 changes: 16 additions & 7 deletions vk_api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,21 @@ def get_all_iter(self, method, max_count, values=None, key='items',
count = None

while True:
try:
response = vk_get_all_items(
self.vk, method, key, values, count, offset,
offset_mul=-1 if negative_offset else 1
)
except ApiError:
response = vk_get_all_items(
self.vk, method, key, values, count, offset,
offset_mul=-1 if negative_offset else 1
)

if 'execute_errors' in response:
raise VkToolsException(
'Can\'t load items. Check access to requested items'
'Could not load items: {}'.format(
response['execute_errors']
),
response=response
)

response = response['response']

items = response["items"]
items_count += len(items)

Expand Down Expand Up @@ -202,6 +207,7 @@ def get_all_slow(self, method, max_count, values=None, key='items',
vk_get_all_items = VkFunction(
args=('method', 'key', 'values', 'count', 'offset', 'offset_mul'),
clean_args=('method', 'key', 'offset', 'offset_mul'),
return_raw=True,
code='''
var params = %(values)s,
calls = 0,
Expand All @@ -217,6 +223,9 @@ def get_all_slow(self, method, max_count, values=None, key='items',
var response = API.%(method)s(params),
new_count = response.count,
count_diff = (count == null ? 0 : new_count - count);
if (!response) {
return {"_error": 1};
}
if (count_diff < 0) {
offset = offset + count_diff;
Expand Down

0 comments on commit d49c1dc

Please sign in to comment.