Browse Source

Handle non-string errors for ES 2+ support

tags/v1.2.2
Paul Bonser 7 years ago
parent
commit
5d13647d3c
2 changed files with 12 additions and 1 deletions
  1. +7
    -0
      goes.go
  2. +5
    -1
      structs.go

+ 7
- 0
goes.go View File

@@ -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}
}


+ 5
- 1
structs.go View File

@@ -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


Loading…
Cancel
Save