Skip to content

Commit

Permalink
Improve "Service Unavailable" error reporting
Browse files Browse the repository at this point in the history
Service Unavailable can happen before shards are updates (creating
a new index, and then query it before it's created). These errors
are not reported as regular errors, and receives a very generic
errormessage. This commit improves the error message for these errors.

Closes elastic#1596
  • Loading branch information
simendsjo committed Oct 17, 2015
1 parent 13f820c commit b42ff1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private ElasticsearchResponse<Stream> DoElasticsearchCall<T>(TransportRequestSta
return this.StreamToTypedResponse<T>(streamResponse, requestState, bytes);

// If error read error
error = GetErrorFromStream<T>(streamResponse.Response);
error = GetErrorFromStream<T>(streamResponse.Response, streamResponse.HttpStatusCode ?? 0);
var typedResponse = ElasticsearchResponse.CloneFrom<T>(streamResponse, default(T));
this.SetStringOrByteResult(typedResponse, bytes);
return typedResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private Task<ReadResponse<T>> ReturnTypedResponse<T>(ElasticsearchResponse<Strea
var typedResponse = ElasticsearchResponse.CloneFrom<T>(streamResponse, default(T));
if (!isValidResponse)
{
response.Error = GetErrorFromStream<T>(gotStream.Result);
response.Error = GetErrorFromStream<T>(gotStream.Result, streamResponse.HttpStatusCode ?? 0);
this.SetStringOrByteResult(typedResponse, response.Bytes);
if (gotStream.Result != null) gotStream.Result.Close();
response.Response = typedResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,20 @@ protected void SetByteResult(ElasticsearchResponse<byte[]> response, byte[] rawR
response.Response = rawResponse;
}

protected ElasticsearchServerError GetErrorFromStream<T>(Stream stream)
protected ElasticsearchServerError GetErrorFromStream<T>(Stream stream, int httpStatusCode=0)
{
try
{
var e = this._serializer.Deserialize<OneToOneServerException>(stream);
if (e != null && e.status == 0)
{
// Service unavailable isn't reported as a regular error, and
// thus won't be serialized as such. This workaround improves
// the errormessage for these errors.
e.status = httpStatusCode;
if (e.status == 503 && e.error.IsNullOrEmpty())
e.error = "ServiceUnavailableException[Service Unavaliable. Try again later.]";
}
return ElasticsearchServerError.Create(e);
}
// ReSharper disable once EmptyGeneralCatchClause
Expand Down

0 comments on commit b42ff1d

Please sign in to comment.