aboutsummaryrefslogtreecommitdiff
path: root/bridge.go
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-13 15:38:28 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-13 15:38:28 -0500
commit53ff4073d99569177348dbc3a6e46c9008767e93 (patch)
treea97f62a7640daf0dc71827a746805039b3861595 /bridge.go
parent22608c316da825445dddd5e42adc3f771506ffe2 (diff)
Cleaned up Bridge.CreateUser
Diffstat (limited to 'bridge.go')
-rw-r--r--bridge.go20
1 files changed, 7 insertions, 13 deletions
diff --git a/bridge.go b/bridge.go
index 04f34d5..878494f 100644
--- a/bridge.go
+++ b/bridge.go
@@ -129,6 +129,9 @@ func HandleResponse(resp *http.Response) ([]byte, io.Reader, error) {
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))
+ }
return body, reader, nil
}
@@ -175,22 +178,13 @@ func (self *Bridge) GetInfo() (BridgeInfo, error) {
}
// CreateUser posts to ./api on the bridge to create a new whitelisted user.
-func (bridge *Bridge) CreateUser(deviceType string) (string, error) {
- // Send an HTTP POST with the body content
+func (bridge *Bridge) CreateUser(deviceType string) error {
params := map[string]string{"devicetype": deviceType}
- body, _, err := bridge.Post("/api", params)
+ _, _, err := bridge.Post("/api", params)
if err != nil {
- return "", err
- }
-
- // Parse the result and return it
- result := string(body)
- errFound := strings.Contains(result, "error")
- noLink := strings.Contains(result, "link button not pressed")
- if errFound && noLink {
- return "", errors.New("Bridge link button not pressed.")
+ return err
}
- return "", nil
+ return nil
}
// Log the date, time, file location, line number, and function.