Skip to content

Commit

Permalink
Ignore errors from API
Browse files Browse the repository at this point in the history
  • Loading branch information
dcondomitti committed Mar 18, 2019
1 parent 6458965 commit 1ad41ce
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func eventCmd(c *cli.Context) error {
resp, err := client.Client.Changes.PostV1ChangesEvents(params, client.Auth)

if err != nil {
return err
return handleError(c, err)
}

fmt.Println(fmt.Sprintf("Created change event %s", resp.Payload.ID))
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func executeCmd(c *cli.Context) error {
resp, err := client.Client.Changes.PostV1ChangesEvents(params, client.Auth)

if err != nil {
return err
return handleError(c, err)
}

fmt.Println(fmt.Sprintf("Created change event %s", resp.Payload.ID))

if cErr != nil {
return cErr
return handleError(c, cErr)
}

return nil
Expand Down
16 changes: 9 additions & 7 deletions pkg/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
)

type configFile struct {
APIKey string `yaml:"apiKey"`
APIHost string `yaml:"apiHost"`
Debug bool `yaml:"debug"`
Identities string `yaml:"identities"`
Labels string `yaml:"labels"`
Environment string `yaml:"environment"`
Service string `yaml:"service"`
APIKey string `yaml:"apiKey"`
APIHost string `yaml:"apiHost"`
Debug bool `yaml:"debug"`
IgnoreErrors bool `yaml:"ignoreErrors"`
Identities string `yaml:"identities"`
Labels string `yaml:"labels"`
Environment string `yaml:"environment"`
Service string `yaml:"service"`
}

func initCmd(c *cli.Context) error {
Expand All @@ -35,6 +36,7 @@ func initCmd(c *cli.Context) error {
}

config.Debug = c.GlobalBool("debug")
config.IgnoreErrors = c.GlobalBool("ignoreErrors")

if len(c.String("identities")) > 0 {
config.Identities = c.String("identities")
Expand Down
8 changes: 8 additions & 0 deletions pkg/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,11 @@ func parseConfigFile(c *cli.Context) error {

return nil
}

func handleError(c *cli.Context, err error) error {
fmt.Println(err.Error())
if c.GlobalBool("ignoreErrors") {
return nil
}
return err
}

0 comments on commit 1ad41ce

Please sign in to comment.