File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -149,9 +149,10 @@ def __next__(self):
149
149
150
150
151
151
class SyncResponseIterator (object ):
152
- def __init__ (self , it , wrapper ):
152
+ def __init__ (self , it , wrapper , error_converter = None ):
153
153
self .it = it
154
154
self .wrapper = wrapper
155
+ self .error_converter = error_converter
155
156
156
157
def cancel (self ):
157
158
self .it .cancel ()
@@ -161,9 +162,16 @@ def __iter__(self):
161
162
return self
162
163
163
164
def _next (self ):
164
- res = self .wrapper (next (self .it ))
165
+ try :
166
+ res = self .wrapper (next (self .it ))
167
+ except BaseException as e :
168
+ if self .error_converter :
169
+ raise self .error_converter (e ) from e
170
+ raise e
171
+
165
172
if res is not None :
166
173
return res
174
+
167
175
return self ._next ()
168
176
169
177
def next (self ):
Original file line number Diff line number Diff line change 19
19
from .transaction import QueryTxContext
20
20
21
21
from .._constants import DEFAULT_INITIAL_RESPONSE_TIMEOUT , DEFAULT_LONG_STREAM_TIMEOUT
22
+ from .._errors import stream_error_converter
22
23
23
24
24
25
logger = logging .getLogger (__name__ )
@@ -362,12 +363,13 @@ def execute(
362
363
)
363
364
364
365
return base .SyncResponseContextIterator (
365
- stream_it ,
366
- lambda resp : base .wrap_execute_query_response (
366
+ it = stream_it ,
367
+ wrapper = lambda resp : base .wrap_execute_query_response (
367
368
rpc_state = None ,
368
369
response_pb = resp ,
369
370
session_state = self ._state ,
370
371
session = self ,
371
372
settings = self ._settings ,
372
373
),
374
+ error_converter = stream_error_converter ,
373
375
)
Original file line number Diff line number Diff line change 16
16
from ..connection import _RpcState as RpcState
17
17
18
18
from . import base
19
+ from .._errors import stream_error_converter
19
20
from ..settings import BaseRequestSettings
20
21
21
22
logger = logging .getLogger (__name__ )
@@ -500,14 +501,15 @@ def execute(
500
501
)
501
502
502
503
self ._prev_stream = base .SyncResponseContextIterator (
503
- stream_it ,
504
- lambda resp : base .wrap_execute_query_response (
504
+ it = stream_it ,
505
+ wrapper = lambda resp : base .wrap_execute_query_response (
505
506
rpc_state = None ,
506
507
response_pb = resp ,
507
508
session_state = self ._session_state ,
508
509
tx = self ,
509
510
commit_tx = commit_tx ,
510
511
settings = self .session ._settings ,
511
512
),
513
+ error_converter = stream_error_converter ,
512
514
)
513
515
return self ._prev_stream
You can’t perform that action at this time.
0 commit comments