Skip to content

Commit

Permalink
Merge pull request #21 from pusher/handle-login-errors-better
Browse files Browse the repository at this point in the history
add handling for 401 and 404s
  • Loading branch information
Hugo Vieira authored Dec 7, 2017
2 parents 2ed9b73 + 50c6235 commit d785a04
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 5 additions & 1 deletion api/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ func basicAuthRequest(path string, username string, password string) ([]byte, er
}
defer resp.Body.Close()

if resp.StatusCode < 200 || 400 <= resp.StatusCode {
if resp.StatusCode == 401 {
return nil, fmt.Errorf("invalid username or password")
} else if resp.StatusCode == 404 {
return nil, fmt.Errorf("no api key associated with the account, please visit https://dashboard.pusher.com/accounts/edit to add one")
} else if resp.StatusCode < 200 || 400 <= resp.StatusCode {
return nil, fmt.Errorf("unexpected status code %d", resp.StatusCode)
}

Expand Down
2 changes: 1 addition & 1 deletion api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func GetAllTokensForApp(appId string) ([]AppToken, error) {
tokens := []AppToken{}
err = json.Unmarshal([]byte(response), &tokens)
if err != nil {
return nil, errors.New("That app ID wasn't recognised as linked to your account.")
return nil, errors.New("that app ID wasn't recognised as linked to your account")
}
return tokens, nil
}
Expand Down
5 changes: 1 addition & 4 deletions commands/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ var Login = &cobra.Command{
// check if the user/pass can get an API key
apikey, err := api.GetAPIKey(email, password)
if err != nil {
panic("Could not get API key: " + err.Error())
}
if apikey == "" {
fmt.Println("There is No API key associated with those account details. Make sure you've set up your API key in the Admin Dashboard, and that are your details are correct.")
fmt.Println("Couldn't get API key: " + err.Error())
return
}
fmt.Println("Got your API key!")
Expand Down

0 comments on commit d785a04

Please sign in to comment.