Skip to content

Commit

Permalink
fix(cmd) ensure error checking before checking for response code
Browse files Browse the repository at this point in the history
If there is an error connecting with Kong, because error is not checked
before looking at status code, it will lead to a nil pointer panic.

Also, as a safeguard, a check has been added to ensure that the returned
status code is 200 indeed.

Fix #95
  • Loading branch information
hbagdi committed Nov 5, 2019
1 parent 17a7342 commit 7be2606
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ func checkWorkspace(config utils.KongClientConfig) error {
return err
}
resp, err := client.Do(nil, req, nil)
if err != nil {
return errors.Wrapf(err, "checking workspace '%v' in Kong", workspace)
}
if resp.StatusCode == 404 {
return errors.Errorf("workspace '%v' does not exist in Kong, "+
"please create it before running decK.", workspace)
}
if err != nil {
return errors.Wrapf(err, "checking workspace '%v' in Kong", workspace)
if resp.StatusCode != 200 {
return errors.Errorf("unexpected error code while retrieving "+
"workspace '%v' : %v", workspace, resp.StatusCode)
}
return nil
}
Expand Down

0 comments on commit 7be2606

Please sign in to comment.