From 0a35db8fd061247b1db20fde92237f02a4e6882c Mon Sep 17 00:00:00 2001 From: Ken Cochrane Date: Fri, 15 Mar 2013 14:41:55 -0700 Subject: [PATCH] added more debugging/ error catching --- auth/auth.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 4224a686d5..8f34904247 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -89,16 +89,26 @@ func Login(authConfig AuthConfig) (string, error) { reqStatusCode := 0 var status string var reqBody []byte - jsonBody, _ := json.Marshal(authConfig) + jsonBody, err := json.Marshal(authConfig) + if err != nil { + errMsg = fmt.Sprintf("Config Error: %s", err) + return "", errors.New(errMsg) + } + b := strings.NewReader(string(jsonBody)) req1, err := http.Post(REGISTRY_SERVER+"/v1/users", "application/json; charset=utf-8", b) if err != nil { - return "", err + errMsg = fmt.Sprintf("Server Error: %s", err) + return "", errors.New(errMsg) } - defer req1.Body.Close() - reqBody, _ = ioutil.ReadAll(req1.Body) reqStatusCode = req1.StatusCode + defer req1.Body.Close() + reqBody, err = ioutil.ReadAll(req1.Body) + if err != nil { + errMsg = fmt.Sprintf("Server Error: [%s] %s", reqStatusCode, err) + return "", errors.New(errMsg) + } if reqStatusCode == 201 { status = "Account Created\n"