From f1cf5074f568c4b853d6ac91c358babdbb12a544 Mon Sep 17 00:00:00 2001 From: Ken Cochrane Date: Thu, 14 Mar 2013 18:43:02 -0700 Subject: [PATCH] cleaned up the code a little --- auth/auth.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index e2db6d857d..822c1f8540 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -92,14 +92,14 @@ func Login(authConfig AuthConfig) (string, error) { jsonBody, _ := json.Marshal(authConfig) b := strings.NewReader(string(jsonBody)) req1, err := http.Post(REGISTRY_SERVER+"/v1/users", "application/json; charset=utf-8", b) - if err == nil { - body, _ := ioutil.ReadAll(req1.Body) - reqStatusCode = req1.StatusCode - reqBody = body - req1.Body.Close() - } else { + if err != nil { return "", err } + + reqBody, _ = ioutil.ReadAll(req1.Body) + reqStatusCode = req1.StatusCode + req1.Body.Close() + if reqStatusCode == 201 { status = "Account Created\n" storeConfig = true @@ -121,12 +121,16 @@ func Login(authConfig AuthConfig) (string, error) { status = "Login Succeeded\n" storeConfig = true } else { - storeConfig = false - status = fmt.Sprintf("Error: %s\n", body) + status = fmt.Sprintf("Login Error: %s\n", body) + return "", errors.New(status) } } else { - status = fmt.Sprintf("Error: %s\n", reqBody) + status = fmt.Sprintf("Registration Error: %s\n", reqBody) + return "", errors.New(status) } + } else { + status = fmt.Sprintf("Error: %s : %s \n", reqStatusCode, reqBody) + return "", errors.New(status) } if storeConfig { authStr := EncodeAuth(authConfig)