Skip to content

Commit

Permalink
Make error message more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
jtyr committed Apr 23, 2021
1 parent f0800d0 commit 18f77bb
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 22 deletions.
3 changes: 1 addition & 2 deletions pkg/apikey/apikeyCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apikey

import (
"encoding/json"
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand Down Expand Up @@ -37,7 +36,7 @@ func (a *APIKey) Create() (string, string, error) {
body, statusCode, err := client.Post(data)
if err != nil {
if statusCode == 409 {
return "", "", errors.New("API key with this name already exists")
return "", "", fmt.Errorf("API key with this name already exists: %s", err)
}

return "", "", err
Expand Down
3 changes: 1 addition & 2 deletions pkg/apikey/apikeyDelete.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package apikey

import (
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand All @@ -20,7 +19,7 @@ func (a *APIKey) Delete() (string, int, error) {
body, statusCode, err := client.Delete()
if err != nil {
if statusCode == 404 {
return "", consts.ExitNotFound, errors.New("API key not found")
return "", consts.ExitNotFound, fmt.Errorf("API key not found: %s", err)
}

return "", consts.ExitError, err
Expand Down
5 changes: 2 additions & 3 deletions pkg/apikey/apikeyList.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apikey

import (
"encoding/json"
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand Down Expand Up @@ -36,9 +35,9 @@ func (a *APIKey) List() (*[]ListItem, string, int, error) {
body, statusCode, err := client.Get()
if err != nil {
if a.Name == "" && statusCode == 404 {
return nil, "", consts.ExitError, errors.New("Org Slug not found")
return nil, "", consts.ExitError, fmt.Errorf("Org Slug not found: %s", err)
} else if a.Name != "" && statusCode == 404 {
return nil, "", consts.ExitNotFound, errors.New("key not found")
return nil, "", consts.ExitNotFound, fmt.Errorf("key not found: %s", err)
}

return nil, "", consts.ExitError, err
Expand Down
3 changes: 1 addition & 2 deletions pkg/grafana/apikey/apikeyCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apikey

import (
"encoding/json"
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand Down Expand Up @@ -61,7 +60,7 @@ func (a *APIKey) Create() (string, string, error) {
body, statusCode, err := client.Post(data)
if err != nil {
if statusCode == 409 {
return "", "", errors.New("API key with this name already exists")
return "", "", fmt.Errorf("API key with this name already exists: %s", err)
}

return "", "", err
Expand Down
4 changes: 2 additions & 2 deletions pkg/grafana/apikey/apikeyDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func (a *APIKey) Delete() (string, int, error) {
}

if keyID == -1 {
return "", consts.ExitNotFound, errors.New("API key not found")
return "", consts.ExitNotFound, errors.New("API key not found in the list of API keys")
}

client.Endpoint = fmt.Sprintf(a.GrafanaEndpoint+"/%d", keyID)

body, statusCode, err := client.Delete()
if err != nil {
if statusCode == 404 {
return "", consts.ExitNotFound, errors.New("API key not found")
return "", consts.ExitNotFound, fmt.Errorf("API key not found: %s", err)
}

return "", consts.ExitError, err
Expand Down
3 changes: 1 addition & 2 deletions pkg/grafana/apikey/apikeyList.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apikey

import (
"encoding/json"
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand Down Expand Up @@ -45,7 +44,7 @@ func (a *APIKey) List() (*ListResp, string, error) {
body, statusCode, err := client.Get()
if err != nil {
if statusCode == 404 {
return nil, "", errors.New("Grafana instance not found")
return nil, "", fmt.Errorf("Grafana instance not found: %s", err)
}

return nil, "", err
Expand Down
3 changes: 1 addition & 2 deletions pkg/grafana/grafanaRestart.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package grafana

import (
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand All @@ -19,7 +18,7 @@ func (g *Grafana) Restart() (string, error) {
body, statusCode, err := client.Post(nil)
if err != nil {
if statusCode == 404 {
return "", errors.New("Stack Slug not found")
return "", fmt.Errorf("Stack Slug not found: %s", err)
}

return "", err
Expand Down
3 changes: 1 addition & 2 deletions pkg/stack/stackCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package stack

import (
"encoding/json"
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand Down Expand Up @@ -32,7 +31,7 @@ func (s *Stack) Create() (*ListItem, string, error) {
body, statusCode, err := client.Post(data)
if err != nil {
if statusCode == 409 {
return nil, "", errors.New("stack with this name already exists")
return nil, "", fmt.Errorf("stack with this name already exists: %s", err)
}

return nil, "", err
Expand Down
3 changes: 1 addition & 2 deletions pkg/stack/stackDelete.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package stack

import (
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand All @@ -20,7 +19,7 @@ func (s *Stack) Delete() (string, int, error) {
body, statusCode, err := client.Delete()
if err != nil {
if statusCode == 404 {
return "", consts.ExitNotFound, errors.New("API key not found")
return "", consts.ExitNotFound, fmt.Errorf("API key not found: %s", err)
}

return "", consts.ExitError, err
Expand Down
5 changes: 2 additions & 3 deletions pkg/stack/stackList.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package stack

import (
"encoding/json"
"errors"
"fmt"

_client "github.com/jtyr/gcapi/pkg/client"
Expand Down Expand Up @@ -46,9 +45,9 @@ func (s *Stack) List() (*[]ListItem, string, int, error) {
body, statusCode, err := client.Get()
if err != nil {
if s.StackSlug == "" && statusCode == 404 {
return nil, "", consts.ExitError, errors.New("Org Slug not found")
return nil, "", consts.ExitError, fmt.Errorf("Org Slug not found: %s", err)
} else if s.StackSlug != "" && statusCode == 404 {
return nil, "", consts.ExitNotFound, errors.New("Stack not found")
return nil, "", consts.ExitNotFound, fmt.Errorf("Stack not found: %s", err)
}

return nil, "", consts.ExitError, err
Expand Down

0 comments on commit 18f77bb

Please sign in to comment.