From 22cd1baa11a7c715b2a675e67bb3956662bec4d8 Mon Sep 17 00:00:00 2001 From: nikkiing <1031497516@qq.com> Date: Tue, 16 May 2023 14:45:40 +0800 Subject: [PATCH] es_error --- pkg/es/es_error.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/es/es_error.go b/pkg/es/es_error.go index 6729854..81ac1ef 100644 --- a/pkg/es/es_error.go +++ b/pkg/es/es_error.go @@ -1,18 +1,19 @@ package es import ( + "context" "encoding/json" "gitea.drugeyes.vip/pharnexbase/utils/glog/v1" "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() { var e map[string]interface{} 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(), e["error"].(map[string]interface{})["type"], e["error"].(map[string]interface{})["reason"],