Skip to content

Commit d49c1dc

Browse files
committed
Update exception in VkTools.get_all_iter
1 parent 571bb92 commit d49c1dc

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

vk_api/exceptions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ class VkAudioUrlDecodeError(VkAudioException):
169169

170170

171171
class VkToolsException(VkApiError):
172-
pass
172+
def __init__(self, *args, response=None):
173+
super().__init__(*args)
174+
self.response = response
173175

174176

175177
class VkRequestsPoolException(Exception):

vk_api/tools.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,21 @@ def get_all_iter(self, method, max_count, values=None, key='items',
6161
count = None
6262

6363
while True:
64-
try:
65-
response = vk_get_all_items(
66-
self.vk, method, key, values, count, offset,
67-
offset_mul=-1 if negative_offset else 1
68-
)
69-
except ApiError:
64+
response = vk_get_all_items(
65+
self.vk, method, key, values, count, offset,
66+
offset_mul=-1 if negative_offset else 1
67+
)
68+
69+
if 'execute_errors' in response:
7070
raise VkToolsException(
71-
'Can\'t load items. Check access to requested items'
71+
'Could not load items: {}'.format(
72+
response['execute_errors']
73+
),
74+
response=response
7275
)
7376

77+
response = response['response']
78+
7479
items = response["items"]
7580
items_count += len(items)
7681

@@ -202,6 +207,7 @@ def get_all_slow(self, method, max_count, values=None, key='items',
202207
vk_get_all_items = VkFunction(
203208
args=('method', 'key', 'values', 'count', 'offset', 'offset_mul'),
204209
clean_args=('method', 'key', 'offset', 'offset_mul'),
210+
return_raw=True,
205211
code='''
206212
var params = %(values)s,
207213
calls = 0,
@@ -217,6 +223,9 @@ def get_all_slow(self, method, max_count, values=None, key='items',
217223
var response = API.%(method)s(params),
218224
new_count = response.count,
219225
count_diff = (count == null ? 0 : new_count - count);
226+
if (!response) {
227+
return {"_error": 1};
228+
}
220229
221230
if (count_diff < 0) {
222231
offset = offset + count_diff;

0 commit comments

Comments
 (0)