@@ -152,13 +152,9 @@ export class ClusterAwareReaderFailoverHandler implements ReaderFailoverHandler
152152 return result ;
153153 }
154154 } catch ( error ) {
155- if ( error instanceof AggregateError && error . message . includes ( "All promises were rejected" ) ) {
156- // ignore and try the next batch
157- } else {
158- // Failover has failed.
159- this . taskHandler . setSelectedConnectionAttemptTask ( failoverTaskId , ClusterAwareReaderFailoverHandler . FAILOVER_FAILED ) ;
160- throw error ;
161- }
155+ // Failover has failed.
156+ this . taskHandler . setSelectedConnectionAttemptTask ( failoverTaskId , ClusterAwareReaderFailoverHandler . FAILOVER_FAILED ) ;
157+ throw error ;
162158 }
163159
164160 await sleep ( 1000 ) ;
@@ -184,7 +180,7 @@ export class ClusterAwareReaderFailoverHandler implements ReaderFailoverHandler
184180 throw new AwsWrapperError ( "Connection attempt task timed out." ) ;
185181 } )
186182 . catch ( ( error ) => {
187- if ( error instanceof InternalQueryTimeoutError || ( error instanceof AggregateError && error . message . includes ( "All promises were rejected" ) ) ) {
183+ if ( error instanceof InternalQueryTimeoutError ) {
188184 // ignore so the next task batch can be attempted
189185 return ClusterAwareReaderFailoverHandler . FAILED_READER_FAILOVER_RESULT ;
190186 }
@@ -207,7 +203,26 @@ export class ClusterAwareReaderFailoverHandler implements ReaderFailoverHandler
207203 tasks . push ( secondTask . call ( ) ) ;
208204 }
209205
210- return await Promise . any ( tasks ) ;
206+ return await Promise . any ( tasks ) . catch ( ( error : AggregateError ) => {
207+ let errors : string = "" ;
208+ for ( const e of error . errors ) {
209+ // Propagate errors that are not caused by network errors.
210+ if ( ! this . pluginService . isNetworkError ( e ) ) {
211+ errors += `\n\t${ e } - ${ e . message } ` ;
212+ }
213+ }
214+ if ( errors ) {
215+ const awsWrapperError = new AwsWrapperError (
216+ Messages . get (
217+ "ClusterAwareReaderFailoverHandler.batchFailed" ,
218+ `[${ hosts [ i ] . hostId } ${ numTasks === 2 ? `, ${ hosts [ i + 1 ] . hostId } ` : `` } ]` ,
219+ `[\n${ errors } \n]`
220+ )
221+ ) ;
222+ return new ReaderFailoverResult ( null , null , false , awsWrapperError ) ;
223+ }
224+ return new ReaderFailoverResult ( null , null , false , undefined ) ;
225+ } ) ;
211226 }
212227
213228 getReaderHostsByPriority ( hosts : HostInfo [ ] ) : HostInfo [ ] {
@@ -321,18 +336,9 @@ class ConnectionAttemptTask {
321336 this . taskHandler . setSelectedConnectionAttemptTask ( this . failoverTaskId , this . taskId ) ;
322337 return new ReaderFailoverResult ( this . targetClient , this . newHost , true , undefined , this . taskId ) ;
323338 }
324- await this . pluginService . abortTargetClient ( this . targetClient ) ;
325- return new ReaderFailoverResult ( null , null , false , undefined , this . taskId ) ;
339+ throw new AwsWrapperError ( Messages . get ( "ClusterAwareReaderFailoverHandler.selectedTaskChosen" , this . newHost . host ) ) ;
326340 } catch ( error ) {
327341 this . pluginService . setAvailability ( this . newHost . allAliases , HostAvailability . NOT_AVAILABLE ) ;
328- if ( error instanceof Error ) {
329- // Propagate errors that are not caused by network errors.
330- if ( ! this . pluginService . isNetworkError ( error ) ) {
331- return new ReaderFailoverResult ( null , null , false , error , this . taskId ) ;
332- }
333-
334- return new ReaderFailoverResult ( null , null , false , undefined , this . taskId ) ;
335- }
336342 throw error ;
337343 } finally {
338344 await this . performFinalCleanup ( ) ;
0 commit comments