Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #2269

Merged
merged 1 commit into from
Apr 4, 2024
Merged

Fix bug #2269

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions adapter/internal/controlplane/eventPublisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ func sendData() {
continue
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if resp.StatusCode == http.StatusServiceUnavailable {
body, _ := ioutil.ReadAll(resp.Body)
loggers.LoggerAPK.Errorf("Error: Unexpected status code: %d, received message: %s, retrying after %d seconds", resp.StatusCode, string(body), retryInterval)
// Sleep for some time before retrying
time.Sleep(time.Second * retryInterval)
Expand All @@ -189,17 +189,20 @@ func sendData() {
}
delete(apiHashMap, event.API.APIHash)
var responseMap map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&responseMap)
if err != nil {
if err := json.Unmarshal([]byte(body), &responseMap); err != nil {
loggers.LoggerAPK.Errorf("Could not decode response body as json. body: %+v", resp.Body)
break
}
// Assuming the response contains an ID field, you can extract it like this:
id, ok := responseMap["id"].(string)
revisionID, revisionOk := responseMap["revisionID"].(string)
if !ok || !revisionOk {
loggers.LoggerAPK.Errorf("Id or/both revision Id field not present in response body. encoded body: %+v", responseMap)
if !ok {
loggers.LoggerAPK.Errorf("Id field not present in response body. encoded body: %+v", responseMap)
id = ""
// break
}
if !revisionOk {
loggers.LoggerAPK.Errorf("Revision field not present in response body. encoded body: %+v", responseMap)
revisionID = ""
// break
}
Expand Down
Loading