Skip to content

Async methods throw exceptions on all 4xx/5xx errors #654

@Aaronaught

Description

@Aaronaught

The documentation states that HTTP errors do not throw exceptions, and this is true for the synchronous methods and was true in the much older (0.20) version of NEST.

However, in the current version (1.0.0-beta1), the async methods will always throw an exception if a 4xx/5xx status is encountered.

Simple repro: execute await client.Raw.DeleteAsync(index, type, id) where the combination of index, type, id points to a document that doesn't exist. This will generate a 404 error and subsequently throw a MaxRetryException.

Stepping further into the source, the retry logic is being triggered because SuccessOrKnownError is false on the response, which is because the HttpStatusCode is actually null. I think the exception is actually bubbling up directly from the WebRequest.EndGetResponse and simply not being caught properly by the task continuation logic.

At the moment I can't use the async methods because of this. Even doing a HEAD request (i.e. DocumentExistsAsync) will throw an exception on a 404, which doesn't make a whole lot of sense.

I assume this is a bug and not an intentional design change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions