@@ -172,10 +172,10 @@ export abstract class Connection {
172172
173173 abstract cancelAsyncQuery ( token : string ) : Promise < void > ;
174174
175- async execute (
175+ protected async prepareAndExecuteQuery (
176176 query : string ,
177- executeQueryOptions : ExecuteQueryOptions = { }
178- ) : Promise < Statement > {
177+ executeQueryOptions : ExecuteQueryOptions
178+ ) : Promise < { formattedQuery : string ; response : Response } > {
179179 const { httpClient } = this . context ;
180180
181181 executeQueryOptions . response = {
@@ -213,14 +213,8 @@ export abstract class Connection {
213213
214214 try {
215215 const response = await request . ready ( ) ;
216- const text = await response . text ( ) ;
217216 await this . processHeaders ( response . headers ) ;
218- await this . throwErrorIfErrorBody ( text , response ) ;
219- return new Statement ( this . context , {
220- query : formattedQuery ,
221- text,
222- executeQueryOptions
223- } ) ;
217+ return { formattedQuery, response } ;
224218 } catch ( error ) {
225219 // In case it was a set query, remove set parameter if query fails
226220 if ( setKey . length > 0 ) {
@@ -232,6 +226,24 @@ export abstract class Connection {
232226 }
233227 }
234228
229+ async execute (
230+ query : string ,
231+ executeQueryOptions : ExecuteQueryOptions = { }
232+ ) : Promise < Statement > {
233+ const { formattedQuery, response } = await this . prepareAndExecuteQuery (
234+ query ,
235+ executeQueryOptions
236+ ) ;
237+
238+ const text = await response . text ( ) ;
239+ await this . throwErrorIfErrorBody ( text , response ) ;
240+ return new Statement ( this . context , {
241+ query : formattedQuery ,
242+ text,
243+ executeQueryOptions
244+ } ) ;
245+ }
246+
235247 protected async throwErrorIfErrorBody ( text : string , response : Response ) {
236248 // Hack, but looks like this is a limitation of the fetch API
237249 // In order to read the body here and elesewhere, we need to clone the response
0 commit comments