mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-15 01:07:34 +00:00
Update logging to the common logging format for all the projects.
This commit is contained in:
+10
-10
@@ -14,7 +14,7 @@ func (c *BaseClient) executeQuery(query []byte, headers any) (result any, err er
|
||||
var queryResult queryResults
|
||||
httpRequest, err := http.NewRequest("POST", c.endpoint, bytes.NewBuffer(query))
|
||||
if err != nil {
|
||||
c.Logger.Error(c, "Error while creating http request;", "error", err.Error())
|
||||
c.Logger.Error("Error while creating http request;", map[string]interface{}{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (c *BaseClient) executeQuery(query []byte, headers any) (result any, err er
|
||||
func() error {
|
||||
httpResponse, err = c.client.Do(httpRequest)
|
||||
if err != nil {
|
||||
c.Logger.Error(c, "Error while executing http request;", "error", err.Error())
|
||||
c.Logger.Error("Error while executing http request;", map[string]interface{}{"error": err.Error()})
|
||||
return err
|
||||
}
|
||||
defer io.Copy(io.Discard, httpResponse.Body) // equivalent to `cp body /dev/null`
|
||||
@@ -45,20 +45,20 @@ func (c *BaseClient) executeQuery(query []byte, headers any) (result any, err er
|
||||
|
||||
body, err := io.ReadAll(httpResponse.Body)
|
||||
if err != nil {
|
||||
c.Logger.Error(c, "Error while reading http response;", "error", err.Error())
|
||||
c.Logger.Error("Error while reading http response;", map[string]interface{}{"error": err.Error()})
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &queryResult)
|
||||
if err != nil {
|
||||
c.Logger.Error(c, "Error while unmarshalling http response;", "error", err.Error())
|
||||
c.Logger.Error("Error while unmarshalling http response;", map[string]interface{}{"error": err.Error()})
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
retry.OnRetry(func(n uint, err error) {
|
||||
c.Logger.Error(c, "Retrying query", "error", err.Error())
|
||||
c.Logger.Error("Retrying query", map[string]interface{}{"error": err.Error()})
|
||||
}),
|
||||
retry.Attempts(uint(retries_available)),
|
||||
retry.DelayType(retry.BackOffDelay),
|
||||
@@ -76,29 +76,29 @@ func (q *queryExecutor) execute() {
|
||||
if q.should_cache {
|
||||
cachedResponse := q.client.cacheLookup(q.hash)
|
||||
if cachedResponse != nil {
|
||||
q.client.Logger.Debug(q.client, "Found cached response")
|
||||
q.client.Logger.Debug("Found cached response", map[string]interface{}{"hash": q.hash})
|
||||
q.result.data = q.client.decodeResponse(cachedResponse)
|
||||
return // return cached response
|
||||
} else {
|
||||
q.client.Logger.Debug(q.client, "No cached response found")
|
||||
q.client.Logger.Debug("Cache miss", map[string]interface{}{"hash": q.hash})
|
||||
}
|
||||
}
|
||||
|
||||
if q.retries_enabled {
|
||||
q.client.Logger.Debug(q.client, "Retries enabled")
|
||||
q.client.Logger.Debug("Retries enabled")
|
||||
q.client.retries.enabled = true
|
||||
}
|
||||
|
||||
response, err := q.client.executeQuery(q.query, q.headers)
|
||||
if err != nil {
|
||||
q.client.Logger.Error(q.client, "Error while executing query;", "error", err.Error())
|
||||
q.client.Logger.Error("Error while executing query;", map[string]interface{}{"error": err.Error()})
|
||||
q.result.errors = err
|
||||
return
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
q.client.Logger.Error(q.client, "Error while converting to json;", "error", err.Error())
|
||||
q.client.Logger.Error("Error while converting to json;", map[string]interface{}{"error": err.Error()})
|
||||
q.result.errors = err
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user