Skip to content

Commit

Permalink
Improved error handling logic for upgrade agent (#87)
Browse files Browse the repository at this point in the history
Signed-off-by: Saranya-jena <[email protected]>

Signed-off-by: Saranya-jena <[email protected]>
  • Loading branch information
Saranya-jena authored Aug 12, 2022
1 parent 3f5ac08 commit 72bc309
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions pkg/apis/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@ import (
)

type manifestData struct {
Data data `json:"data"`
Data data `json:"data"`
Errors []struct {
Message string `json:"message"`
Path []string `json:"path"`
} `json:"errors"`
}

type data struct {
GetManifest string `json:"getManifest"`
}

type ClusterData struct {
Data GetAgentDetails `json:"data"`
Data GetAgentDetails `json:"data"`
Errors []struct {
Message string `json:"message"`
Path []string `json:"path"`
} `json:"errors"`
}

type GetAgentDetails struct {
Expand Down Expand Up @@ -61,6 +69,11 @@ func UpgradeAgent(c context.Context, cred types.Credentials, projectID string, c
if err != nil {
return "", err
}
if len(agent.Errors) > 0 {
return "", errors.New(agent.Errors[0].Message)
}
} else {
return "", errors.New(resp.Status)
}

// Query to fetch upgraded manifest from the server
Expand All @@ -85,6 +98,10 @@ func UpgradeAgent(c context.Context, cred types.Credentials, projectID string, c
return "", err
}

if len(manifest.Errors) > 0 {
return "", errors.New(manifest.Errors[0].Message)
}

// To write the manifest data into a temporary file
err = ioutil.WriteFile("chaos-delegate-manifest.yaml", []byte(manifest.Data.GetManifest), 0644)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ type GetServerVersionData struct {

// GetServerVersion fetches the GQL server version
func GetServerVersion(endpoint string) (ServerVersionResponse, error) {
query := `{query”:“query{\n getServerVersion{\n key value\n }\n}}`
query := `{"query":"query{\n getServerVersion{\n key value\n }\n}"}`
resp, err := SendRequest(
SendRequestParams{
Endpoint: endpoint + utils.GQLAPIPath,
Expand All @@ -412,6 +412,6 @@ func GetServerVersion(endpoint string) (ServerVersionResponse, error) {
}
return version, nil
} else {
return ServerVersionResponse{}, err
return ServerVersionResponse{}, errors.New(resp.Status)
}
}

0 comments on commit 72bc309

Please sign in to comment.