From 5d13647d3ceafcecade08a1a3ea30ca634cd5495 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Thu, 13 Oct 2016 19:37:40 -0500 Subject: [PATCH] Handle non-string errors for ES 2+ support --- goes.go | 7 +++++++ structs.go | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/goes.go b/goes.go index 330b805..94b3fe4 100644 --- a/goes.go +++ b/goes.go @@ -516,6 +516,13 @@ func (c *Client) Do(r Requester) (*Response, error) { } } + if len(esResp.RawError) > 0 && esResp.RawError[0] == '"' { + json.Unmarshal(esResp.RawError, &esResp.Error) + } else { + esResp.Error = string(esResp.RawError) + } + esResp.RawError = nil + if esResp.Error != "" { return esResp, &SearchError{esResp.Error, esResp.Status} } diff --git a/structs.go b/structs.go index dbfd686..ca08edd 100644 --- a/structs.go +++ b/structs.go @@ -4,7 +4,10 @@ package goes -import "net/http" +import ( + "encoding/json" + "net/http" +) // Client represents a connection to elasticsearch type Client struct { @@ -23,6 +26,7 @@ type Client struct { type Response struct { Acknowledged bool Error string + RawError json.RawMessage `json:"error"` Errors bool Status uint64 Took uint64