Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Elasticsearch.Net/Transport/Transport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System;
using System.Linq;
using System.Net;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pragma as well


namespace Elasticsearch.Net
{
Expand Down Expand Up @@ -190,8 +191,22 @@ private static IApiCallDetails GetMostRecentCallDetails<TResponse>(TResponse res

private void HandleElasticsearchClientException(RequestData data, Exception clientException, IElasticsearchResponse response)
{
if (clientException != null && response.ApiCall.OriginalException == null && response.ApiCall is ApiCallDetails a)
a.OriginalException = clientException;
if (response.ApiCall is ApiCallDetails a)
{
//if original exception was not explicitly set during the pipeline
//set it to the ElasticsearchClientException we created for the bad response
if (clientException != null && a.OriginalException == null)
a.OriginalException = clientException;
//On .NET Core the IConnection implementation throws exceptions on bad responses
//This causes it to behave differently to .NET FULL. We already wrapped the WebExeption
//under ElasticsearchServerException and it exposes way more information as part of it's
//exception message e.g the the root cause of the server error body.
#if FEATURE_HTTPWEBREQUEST
if (a.OriginalException is WebException)
a.OriginalException = clientException;
#endif
}

this.Settings.OnRequestCompleted?.Invoke(response.ApiCall);
if (clientException != null && data.ThrowExceptions) throw clientException;
}
Expand Down