aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-20 11:50:25 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-20 11:50:25 -0500
commit7d1070d12df6e3c9af14f3c0d70586bb019c7430 (patch)
tree7f3c955a616b0b16fb0505022c2053cc1c7804c8
parent3ed62d41690cac5a343636ae6f1ea831a76491ac (diff)
Improved error log system.
-rw-r--r--bridge.go15
-rw-r--r--light_test.go2
2 files changed, 13 insertions, 4 deletions
diff --git a/bridge.go b/bridge.go
index 057250d..2214e58 100644
--- a/bridge.go
+++ b/bridge.go
@@ -88,6 +88,7 @@ func (bridge *Bridge) Post(path string, params interface{}) ([]byte, io.Reader,
// Add the params to the request
request, err := json.Marshal(params)
if err != nil {
+ panic(err)
trace("", err)
return []byte{}, nil, nil
}
@@ -97,7 +98,8 @@ func (bridge *Bridge) Post(path string, params interface{}) ([]byte, io.Reader,
uri := fmt.Sprintf("http://" + bridge.IPAddress + path)
resp, err := http.Post(uri, "text/json", bytes.NewReader(request))
if bridge.Error(resp, err) {
- return []byte{}, nil, nil
+ panic(err)
+ return []byte{}, nil, err
}
return HandleResponse(resp)
}
@@ -129,9 +131,16 @@ func HandleResponse(resp *http.Response) ([]byte, io.Reader, error) {
return []byte{}, nil, err
}
reader := bytes.NewReader(body)
- //log.Println("Handled response:\n------\n", string(body) + "\n------\n")
if strings.Contains(string(body), "error") {
- return []byte{}, nil, errors.New(string(body))
+ errString := string(body)
+ errNum := errString[strings.Index(errString, "type\":")+6 :
+ strings.Index(errString, ",\"address")]
+ errDesc := errString[strings.Index(errString, "description\":\"")+14 :
+ strings.Index(errString, "\"}}")]
+ errOut := fmt.Sprintf("Error type %s: %s.", errNum, errDesc)
+ err = errors.New(errOut)
+ log.Println(err)
+ return []byte{}, nil, err
}
return body, reader, nil
}
diff --git a/light_test.go b/light_test.go
index 086970f..0d486cd 100644
--- a/light_test.go
+++ b/light_test.go
@@ -10,7 +10,7 @@ package hue
import (
"testing"
//"fmt"
- //"time"
+ "time"
)
func TestSetLightState(t *testing.T) {