@@ -202,14 +202,13 @@ def _prepare_execute_args(self, operation):
202202 def _format_parameter_set (self , parameters ):
203203 return [self .prepare_param (k , v ) for k , v in parameters .items ()]
204204
205- def _get_database_error (self , original_error ):
206- # TODO: avoid SHOW ERRORS if on postgres (it's a useless network roundtrip)
207- try :
208- err_res = self ._client .execute_statement (** self ._prepare_execute_args ("SHOW ERRORS" ))
209- err_info = self ._render_response (err_res )["records" ][- 1 ]
210- return DatabaseError (MySQLErrorCodes (err_info [1 ]), err_info [2 ])
211- except self ._client .exceptions .BadRequestException :
212- return DatabaseError (original_error )
205+ def _get_database_error (self , origin_error ):
206+ if getattr (origin_error , "response" , {}).get ("Error" , {}).get ("Message" , "" ).startswith ("Database error code" ):
207+ assert origin_error .response ["Error" ]["Message" ].startswith ("Database error code" )
208+ code , msg = (s .split (": " , 1 )[1 ] for s in origin_error .response ["Error" ]["Message" ].split (". " , 1 ))
209+ return DatabaseError (MySQLErrorCodes (int (code )), msg )
210+ else :
211+ return DatabaseError (origin_error )
213212
214213 def execute (self , operation , parameters = None ):
215214 self ._current_response , self ._iterator , self ._paging_state = None , None , None
@@ -226,7 +225,7 @@ def execute(self, operation, parameters=None):
226225 except self ._client .exceptions .BadRequestException as e :
227226 if "Please paginate your query" in str (e ):
228227 self ._start_paginated_query (execute_statement_args )
229- elif "Database response exceeded size limit" in str (e ):
228+ elif "Database returned more than the allowed response size limit" in str (e ):
230229 self ._start_paginated_query (execute_statement_args , records_per_page = max (1 , self .arraysize // 2 ))
231230 else :
232231 raise self ._get_database_error (e ) from e
@@ -319,7 +318,8 @@ def __iter__(self):
319318 try :
320319 page = self ._client .execute_statement (** next_page_args )
321320 except self ._client .exceptions .BadRequestException as e :
322- if "Database response exceeded size limit" in str (e ) and self ._paging_state ["records_per_page" ] > 1 :
321+ cur_rpp = self ._paging_state ["records_per_page" ]
322+ if "Database returned more than the allowed response size limit" in str (e ) and cur_rpp > 1 :
323323 self .scroll (- self ._paging_state ["records_per_page" ]) # Rewind the cursor to read the page again
324324 logger .debug ("Halving records per page" )
325325 self ._paging_state ["records_per_page" ] //= 2
0 commit comments