Skip to content

Commit a2127de

Browse files
committed
fixed async exceptions bubling appropiately
1 parent 93c9f21 commit a2127de

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Nest/ElasticClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ D descriptor
142142
var mr = r.Exception.InnerException as MaxRetryException;
143143
if (mr != null)
144144
throw mr;
145+
146+
var ae = r.Exception.Flatten();
147+
if (ae.InnerException != null)
148+
throw ae.InnerException;
149+
throw ae;
145150
}
146151
return ResultsSelector<D, Q, R>(r.Result, descriptor);
147152
});

src/Tests/Nest.Tests.Integration/Exceptions/ElasticsearchExceptionTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,24 @@ public void ConnectionException_WithThrowingClient()
3030
.ThrowOnElasticsearchServerExceptions());
3131
var e = Assert.Throws<WebException>(() => client.RootNodeInfo());
3232
}
33+
34+
[Test]
35+
public void ConnectionException_WithClientThatDoesNotThrow_StillThrows_Async()
36+
{
37+
var uri = ElasticsearchConfiguration.CreateBaseUri(9492);
38+
var client = new ElasticClient(new ConnectionSettings(uri).SetTimeout(500));
39+
Assert.Throws<WebException>(async () => await client.RootNodeInfoAsync());
40+
}
3341

42+
[Test]
43+
public void ConnectionException_WithThrowingClient_Async()
44+
{
45+
var uri = ElasticsearchConfiguration.CreateBaseUri(9494);
46+
var client = new ElasticClient(new ConnectionSettings(uri)
47+
.SetTimeout(500)
48+
.ThrowOnElasticsearchServerExceptions());
49+
Assert.Throws<WebException>(async () => await client.RootNodeInfoAsync());
50+
}
3451
[Test]
3552
public void ServerError_Is_Set_ClientThat_DoesNotThow()
3653
{

0 commit comments

Comments
 (0)