@@ -48,12 +48,44 @@ public void ConnectionException_WithThrowingClient_Async()
4848 . ThrowOnElasticsearchServerExceptions ( ) ) ;
4949 Assert . Throws < WebException > ( async ( ) => await client . RootNodeInfoAsync ( ) ) ;
5050 }
51+
52+ [ Test ]
53+ public async void ServerError_Is_Set_ClientThat_DoesNotThow_AndDoesNotExposeRawResponse_Async ( )
54+ {
55+ var uri = ElasticsearchConfiguration . CreateBaseUri ( ) ;
56+ var client = new ElasticClient ( new ConnectionSettings ( uri ) . ExposeRawResponse ( false ) ) ;
57+ Assert . DoesNotThrow ( async ( ) =>
58+ {
59+ var result = await client . SearchAsync < ElasticsearchProject > ( s => s . QueryRaw ( @"{ ""badjson"": {} }" ) ) ;
60+ result . IsValid . Should ( ) . BeFalse ( ) ;
61+ result . ConnectionStatus . HttpStatusCode . Should ( ) . Be ( 400 ) ;
62+ var e = result . ServerError ;
63+ e . Should ( ) . NotBeNull ( ) ;
64+ e . ExceptionType . Should ( ) . Contain ( "SearchPhaseExecutionException" ) ;
65+ } ) ;
66+ }
67+
68+ [ Test ]
69+ public void ServerError_Is_Set_ClientThat_DoesNotThow_AndDoesNotExposeRawResponse ( )
70+ {
71+ var uri = ElasticsearchConfiguration . CreateBaseUri ( ) ;
72+ var client = new ElasticClient ( new ConnectionSettings ( uri ) . ExposeRawResponse ( false ) ) ;
73+ Assert . DoesNotThrow ( ( ) =>
74+ {
75+ var result = client . Search < ElasticsearchProject > ( s => s . QueryRaw ( @"{ ""badjson"": {} }" ) ) ;
76+ result . IsValid . Should ( ) . BeFalse ( ) ;
77+ result . ConnectionStatus . HttpStatusCode . Should ( ) . Be ( 400 ) ;
78+ var e = result . ServerError ;
79+ e . Should ( ) . NotBeNull ( ) ;
80+ e . ExceptionType . Should ( ) . Contain ( "SearchPhaseExecutionException" ) ;
81+ } ) ;
82+ }
5183
5284 [ Test ]
5385 public void ServerError_Is_Set_ClientThat_DoesNotThow ( )
5486 {
5587 var uri = ElasticsearchConfiguration . CreateBaseUri ( ) ;
56- var client = new ElasticClient ( new ConnectionSettings ( uri ) ) ;
88+ var client = new ElasticClient ( new ConnectionSettings ( uri ) . ExposeRawResponse ( true ) ) ;
5789 Assert . DoesNotThrow ( ( ) =>
5890 {
5991 var result = client . Search < ElasticsearchProject > ( s => s . QueryRaw ( @"{ ""badjson"": {} }" ) ) ;
0 commit comments