通用包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
utils/pkg/es/es_error.go

25 lines
608 B

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