From 893695aee05128bbff7c0163fe5e2502756494b7 Mon Sep 17 00:00:00 2001 From: dickeyxxx Date: Tue, 19 Jan 2016 09:44:08 -0800 Subject: [PATCH 1/2] catch 2fa login errors --- login.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/login.go b/login.go index c4bee48b2d..a096659060 100644 --- a/login.go +++ b/login.go @@ -156,21 +156,26 @@ func v2login(email, password, secondFactor string) (string, error) { err = errors.New(errorStr) } ExitIfError(err, false) - if res.StatusCode == 403 { + switch res.StatusCode { + case 200: + var response struct { + APIKey string `json:"api_key"` + } + ExitIfError(res.Body.FromJsonTo(&response), false) + return response.APIKey, nil + case 401: + var response struct { + Error string `json:"error"` + } + ExitIfError(res.Body.FromJsonTo(&response), false) + return "", errors.New(response.Error) + case 403: return v2login(email, password, getString("Two-factor code: ")) - } - if res.StatusCode == 404 { - return "", errors.New("Authentication failure.") - } - if res.StatusCode != 200 { + case 404: + return "", errors.New("Authentication failed.\nEmail or password is not valid.\nCheck your credentials on https://dashboard.heroku.com") + default: return "", errors.New("Invalid response from API.\nAre you behind a proxy?\nhttps://devcenter.heroku.com/articles/using-the-cli#using-an-http-proxy") } - type Doc struct { - APIKey string `json:"api_key"` - } - var doc Doc - ExitIfError(res.Body.FromJsonTo(&doc), false) - return doc.APIKey, nil } func createOauthToken(email, password, secondFactor string) (string, error) { From a5556c4d1c79890b8c324e2d86ae23300472f986 Mon Sep 17 00:00:00 2001 From: dickeyxxx Date: Mon, 25 Jan 2016 11:43:59 -0800 Subject: [PATCH 2/2] show invalid response from login --- login.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/login.go b/login.go index a096659060..3e0513f538 100644 --- a/login.go +++ b/login.go @@ -174,7 +174,9 @@ func v2login(email, password, secondFactor string) (string, error) { case 404: return "", errors.New("Authentication failed.\nEmail or password is not valid.\nCheck your credentials on https://dashboard.heroku.com") default: - return "", errors.New("Invalid response from API.\nAre you behind a proxy?\nhttps://devcenter.heroku.com/articles/using-the-cli#using-an-http-proxy") + body, err := res.Body.ToString() + PrintError(err, false) + return "", fmt.Errorf("Invalid response from API.\nHTTP %d\n%s\n\nAre you behind a proxy?\nhttps://devcenter.heroku.com/articles/using-the-cli#using-an-http-proxy", res.StatusCode, body) } }