|
|
@ -1,18 +1,19 @@ |
|
|
|
package es |
|
|
|
package es |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"gitea.drugeyes.vip/pharnexbase/utils/glog/v1" |
|
|
|
"gitea.drugeyes.vip/pharnexbase/utils/glog/v1" |
|
|
|
"github.com/elastic/go-elasticsearch/v7/esapi" |
|
|
|
"github.com/elastic/go-elasticsearch/v7/esapi" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func IsError(res *esapi.Response) bool { |
|
|
|
func IsError(ctx context.Context, res *esapi.Response) bool { |
|
|
|
if res.IsError() { |
|
|
|
if res.IsError() { |
|
|
|
var e map[string]interface{} |
|
|
|
var e map[string]interface{} |
|
|
|
if err := json.NewDecoder(res.Body).Decode(&e); err != nil { |
|
|
|
if err := json.NewDecoder(res.Body).Decode(&e); err != nil { |
|
|
|
glog.Glog.Error("Error parsing the response body:", err) |
|
|
|
glog.Glog.WithContext(ctx).Error("Error parsing the response body:", err) |
|
|
|
} |
|
|
|
} |
|
|
|
glog.Glog.Errorf("[%s] %s: %s", |
|
|
|
glog.Glog.WithContext(ctx).Errorf("[%s] %s: %s", |
|
|
|
res.Status(), |
|
|
|
res.Status(), |
|
|
|
e["error"].(map[string]interface{})["type"], |
|
|
|
e["error"].(map[string]interface{})["type"], |
|
|
|
e["error"].(map[string]interface{})["reason"], |
|
|
|
e["error"].(map[string]interface{})["reason"], |
|
|
|