# ThrowExceptions() and retries in Nest 6

**URL:** <https://discuss.elastic.co/t/throwexceptions-and-retries-in-nest-6/136265>\
**Category:** Elasticsearch\
**Created:** [June 18, 2018, 9:07am UTC](https://discuss.elastic.co/t/throwexceptions-and-retries-in-nest-6/136265 "2018-06-18T09:07:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![die\_seltsame](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/die_seltsame/32/29303_2.png) [@die\_seltsame](https://discuss.elastic.co/u/die_seltsame)\
**Post date:** [June 18, 2018, 9:07am UTC](https://discuss.elastic.co/t/throwexceptions-and-retries-in-nest-6/136265/1 "2018-06-18T09:07:24Z")

</div>

We are using elasticsearch 6.2.0 and Nest 6.0.0.

We want to use SniffingConnectionPool with request retries. We have `ThrowExceptions()` enabled because we don't want to think abount handling exceptions.

We created test, in which we try to send request to node, that guaranteed to return 500 (NotEnoughMasterException). We expect to make retry to another node. However it fails with exception:

```
Elasticsearch.Net.PipelineException: Failed sniffing cluster state. ---> 
System.AggregateException ---> 
Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node

```

What are we doing wrong? Can we throw exceptions and make retries together?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [June 20, 2018, 2:24am UTC](https://discuss.elastic.co/t/throwexceptions-and-retries-in-nest-6/136265/2 "2018-06-20T02:24:17Z")

</div>

NEST does not retry _all_ exceptions; take a look at the [failover and retries documentation](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/retries-and-failover.html). Essentially, for HTTP response codes in the range 500-599, the client will retry

- `502 Bad Gateway`
- `503 Service Unavailable`
- `504 Gateway Timeout`

The response will have an [audit trail of what the client did](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/audit-trail.html), which can be read along with additional information about the request and response (if available) using [`.DebugInformation`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/debug-information.html) on response.

I suspect the response returned from Elasticsearch for `NotEnoughMasterException` is not to retry, and the [exception](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/unrecoverable-exceptions.html) is thrown.

---

<div class="post-metadata">

**Author:** ![die\_seltsame](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/die_seltsame/32/29303_2.png) [@die\_seltsame](https://discuss.elastic.co/u/die_seltsame)\
**Post date:** [June 20, 2018, 10:41am UTC](https://discuss.elastic.co/t/throwexceptions-and-retries-in-nest-6/136265/3 "2018-06-20T10:41:16Z")

</div>

Thank you, it seems that it really is not to retry

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 18, 2018, 10:41am UTC](https://discuss.elastic.co/t/throwexceptions-and-retries-in-nest-6/136265/4 "2018-07-18T10:41:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
