@@ -515,18 +515,29 @@ private Task<ElasticsearchResponse<Stream>> CallIntoConnectionAsync<T>(Transport
515515 var uri = requestState . CreatePathOnCurrentNode ( ) ;
516516 var postData = requestState . PostData ;
517517 var requestConfiguration = requestState . RequestConfiguration ;
518- switch ( requestState . Method . ToLowerInvariant ( ) )
518+ var method = requestState . Method . ToLowerInvariant ( ) ;
519+ try
519520 {
520- case "head" : return this . Connection . Head ( uri , requestConfiguration ) ;
521- case "get" : return this . Connection . Get ( uri , requestConfiguration ) ;
522- case "post" : return this . Connection . Post ( uri , postData , requestConfiguration ) ;
523- case "put" : return this . Connection . Put ( uri , postData , requestConfiguration ) ;
524- case "delete" :
525- return postData == null || postData . Length == 0
526- ? this . Connection . Delete ( uri , requestConfiguration )
527- : this . Connection . Delete ( uri , postData , requestConfiguration ) ;
521+ switch ( method )
522+ {
523+ case "head" : return this . Connection . Head ( uri , requestConfiguration ) ;
524+ case "get" : return this . Connection . Get ( uri , requestConfiguration ) ;
525+ case "post" : return this . Connection . Post ( uri , postData , requestConfiguration ) ;
526+ case "put" : return this . Connection . Put ( uri , postData , requestConfiguration ) ;
527+ case "delete" :
528+ return postData == null || postData . Length == 0
529+ ? this . Connection . Delete ( uri , requestConfiguration )
530+ : this . Connection . Delete ( uri , postData , requestConfiguration ) ;
531+ default :
532+ throw new Exception ( "Unknown HTTP method " + requestState . Method ) ;
533+ }
534+ }
535+ catch ( Exception e )
536+ {
537+ var tcs = new TaskCompletionSource < ElasticsearchResponse < Stream > > ( ) ;
538+ tcs . SetException ( e ) ;
539+ return tcs . Task ;
528540 }
529- throw new Exception ( "Unknown HTTP method " + requestState . Method ) ;
530541 }
531542
532543 private Task < MemoryStream > Iterate ( IEnumerable < Task > asyncIterator , MemoryStream memoryStream )
0 commit comments