Custom exceptions in Nest

In the documentation it's possible to define custom exceptions via ConnectionConfiguration as said here:

var settings = new ConnectionConfiguration()
    .SetConnectionStatusHandler(r=> {
        if (r.HttpStatusCode == 403)
           throw new MyApplicationNotLoggedInException();
        });

But ConnectionConfiguration is the way of setting up the low level API. Currently I use only Nest and my only option is to redefine ConnectionSettings where my only option is .ThrowExceptions(bool). Is there any option to use the low level api settings in Nest?

ConnectionSettings in NEST implements the same interface as ConnectionConfiguration, so the same methods available on it are also available on ConnectionSettings.

The documentation you're looking at is from 1.x. To throw a custom exception in NEST 2.x onwards would be

var connectionSettings = new ConnectionSettings()
    .OnRequestCompleted(response =>
    {
        if (response.HttpStatusCode == 403)
            throw new MyApplicationNotLoggedInException();
    });

var client = new ElasticClient(connectionSettings);

try 
{
    var searchResponse = client.Search<Message>();
}
catch (MyApplicationNotLoggedInException e)
{
    // 403 error
}

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