@@ -174,7 +174,7 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
174
174
if ( ! SniffingDisabled ( requestState . RequestConfiguration ) )
175
175
SniffIfInformationIsTooOld ( retried ) ;
176
176
177
- IElasticsearchResponse response = null ;
177
+ var aliveResponse = false ;
178
178
179
179
int initialSeed ; bool shouldPingHint ;
180
180
var baseUri = GetNextBaseUri ( requestState , out initialSeed , out shouldPingHint ) ;
@@ -200,7 +200,7 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
200
200
var typedResponse = this . StreamToTypedResponse < T > ( streamResponse , requestState . DeserializationState ) ;
201
201
typedResponse . NumberOfRetries = retried ;
202
202
this . SetErrorDiagnosticsAndPatchSuccess ( requestState , error , typedResponse , streamResponse ) ;
203
- response = typedResponse ;
203
+ aliveResponse = typedResponse . SuccessOrKnownError ;
204
204
return typedResponse ;
205
205
}
206
206
}
@@ -215,7 +215,7 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
215
215
finally
216
216
{
217
217
//make sure we always call markalive on the uri if the connection was succesful
218
- if ( ! seenError && response != null && response . SuccessOrKnownError )
218
+ if ( ! seenError && aliveResponse )
219
219
this . _connectionPool . MarkAlive ( baseUri ) ;
220
220
}
221
221
return RetryRequest < T > ( requestState , baseUri , retried ) ;
@@ -237,27 +237,6 @@ private void SetErrorDiagnosticsAndPatchSuccess<T>(TransportRequestState<T> requ
237
237
}
238
238
}
239
239
240
- private ElasticsearchServerError ThrowOrGetErrorFromStreamResponse < T > ( TransportRequestState < T > requestState ,
241
- ElasticsearchResponse < Stream > streamResponse )
242
- {
243
- ElasticsearchServerError error = null ;
244
- if ( ( ! streamResponse . Success && requestState . RequestConfiguration == null )
245
- || ( ! streamResponse . Success
246
- && requestState . RequestConfiguration != null
247
- && requestState . RequestConfiguration . AllowedStatusCodes . All ( i => i != streamResponse . HttpStatusCode ) ) )
248
- {
249
- if ( streamResponse . Response != null )
250
- error = this . Serializer . Deserialize < ElasticsearchServerError > ( streamResponse . Response ) ;
251
- else
252
- error = new ElasticsearchServerError
253
- {
254
- Status = streamResponse . HttpStatusCode . GetValueOrDefault ( - 1 )
255
- } ;
256
- if ( this . Settings . ThrowOnElasticsearchServerExceptions )
257
- throw new ElasticsearchServerException ( error ) ;
258
- }
259
- return error ;
260
- }
261
240
262
241
private Uri GetNextBaseUri < T > ( TransportRequestState < T > requestState , out int initialSeed , out bool shouldPingHint )
263
242
{
@@ -375,6 +354,8 @@ private Task<ElasticsearchResponse<T>> _doRequestAsyncOrRetry<T>(
375
354
{
376
355
tt . Result . NumberOfRetries = retried ;
377
356
this . SetErrorDiagnosticsAndPatchSuccess ( requestState , error , tt . Result , t . Result ) ;
357
+ if ( tt . Result . SuccessOrKnownError )
358
+ this . _connectionPool . MarkAlive ( baseUri ) ;
378
359
return tt ;
379
360
} ) . Unwrap ( ) ;
380
361
}
@@ -459,7 +440,46 @@ private void SetByteResult(ElasticsearchResponse<byte[]> response, byte[] rawRes
459
440
response . Response = rawResponse ;
460
441
}
461
442
462
- private ElasticsearchResponse < T > StreamToTypedResponse < T > ( ElasticsearchResponse < Stream > streamResponse , object deserializationState )
443
+ private ElasticsearchServerError ThrowOrGetErrorFromStreamResponse < T > (
444
+ TransportRequestState < T > requestState ,
445
+ ElasticsearchResponse < Stream > streamResponse )
446
+ {
447
+ ElasticsearchServerError error = null ;
448
+ if ( ( ! streamResponse . Success && requestState . RequestConfiguration == null )
449
+ || ( ! streamResponse . Success
450
+ && requestState . RequestConfiguration != null
451
+ && requestState . RequestConfiguration . AllowedStatusCodes . All ( i => i != streamResponse . HttpStatusCode ) ) )
452
+ {
453
+
454
+ if ( streamResponse . Response != null && ! this . Settings . KeepRawResponse )
455
+ {
456
+ var e = this . Serializer . Deserialize < OneToOneServerException > ( streamResponse . Response ) ;
457
+ error = ElasticsearchServerError . Create ( e ) ;
458
+ }
459
+ else if ( streamResponse . Response != null && this . Settings . KeepRawResponse )
460
+ {
461
+ var ms = new MemoryStream ( ) ;
462
+ streamResponse . Response . CopyTo ( ms ) ;
463
+ ms . Position = 0 ;
464
+ streamResponse . ResponseRaw = ms . ToArray ( ) ;
465
+ var e = this . Serializer . Deserialize < OneToOneServerException > ( ms ) ;
466
+ error = ElasticsearchServerError . Create ( e ) ;
467
+ ms . Position = 0 ;
468
+ streamResponse . Response = ms ;
469
+ }
470
+ else
471
+ error = new ElasticsearchServerError
472
+ {
473
+ Status = streamResponse . HttpStatusCode . GetValueOrDefault ( - 1 )
474
+ } ;
475
+ if ( this . Settings . ThrowOnElasticsearchServerExceptions )
476
+ throw new ElasticsearchServerException ( error ) ;
477
+ }
478
+ return error ;
479
+ }
480
+ private ElasticsearchResponse < T > StreamToTypedResponse < T > (
481
+ ElasticsearchResponse < Stream > streamResponse ,
482
+ object deserializationState )
463
483
{
464
484
//if the user explicitly wants a stream returned the undisposed stream
465
485
if ( typeof ( Stream ) . IsAssignableFrom ( typeof ( T ) ) )
0 commit comments