diff --git a/cmd/ls.go b/cmd/ls.go index 8383132..1485a90 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -25,7 +25,7 @@ func LsCmd(args CmdArgs) int { selector := args.Flags.String("selector") lights, err := c.ListLights(selector) if err != nil { - fmt.Println(err) + fmt.Printf("fatal: %s\n", err) return 1 } PrintLights(lights) diff --git a/cmd/lume/main.go b/cmd/lume/main.go index 7013cd5..51e3645 100644 --- a/cmd/lume/main.go +++ b/cmd/lume/main.go @@ -47,7 +47,7 @@ func main() { cmd, ok := lumecmd.GetCommand(command) if !ok { - fmt.Println("ERROR") + fmt.Printf("lume: '%s' is not lume command. See 'lume' --help.'\n", command) os.Exit(1) } fs := cmd.Flags diff --git a/cmd/toggle.go b/cmd/toggle.go index 9d54164..c441b93 100644 --- a/cmd/toggle.go +++ b/cmd/toggle.go @@ -24,7 +24,7 @@ func ToggleCmd(args CmdArgs) int { selector := args.Flags.String("selector") r, err := c.Toggle(selector, duration) if err != nil { - fmt.Println(err) + fmt.Printf("fatal: %s\n", err) return 1 } PrintResults(r.Results) diff --git a/lights.go b/lights.go index 5255aa9..5e1a0af 100644 --- a/lights.go +++ b/lights.go @@ -3,7 +3,7 @@ package lifx import ( //"crypto/tls" "encoding/json" - "fmt" + "errors" "net/http" "time" ) @@ -97,7 +97,7 @@ func NewApiError(resp *http.Response) error { if err = json.NewDecoder(resp.Body).Decode(&s); err != nil { return err } - return fmt.Errorf("fatal: %s", s.Error) + return errors.New(s.Error) } func IsApiError(resp *http.Response) bool { @@ -120,6 +120,10 @@ func (c *Client) SetState(selector string, state State) (*Response, error) { } defer resp.Body.Close() + if IsApiError(resp) { + return nil, NewApiError(resp) + } + if state.Fast && resp.StatusCode == http.StatusAccepted { return nil, nil }