change error format
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user