1
0
mirror of https://github.com/writeas/go-writeas.git synced 2025-07-27 18:38:40 +00:00

Rearrange status checks in LogIn

This commit is contained in:
Matt Baer 2018-09-22 22:59:12 +02:00
parent 78fe498545
commit f8191a8ea4

26
auth.go
View File

@ -28,19 +28,21 @@ func (c *Client) LogIn(username, pass string) (*AuthUser, error) {
} }
status := env.Code status := env.Code
if status == http.StatusOK { if status != http.StatusOK {
c.SetToken(u.AccessToken) if status == http.StatusBadRequest {
return u, nil return nil, fmt.Errorf("Bad request: %s", env.ErrorMessage)
} else if status == http.StatusBadRequest { } else if status == http.StatusUnauthorized {
return nil, fmt.Errorf("Bad request: %s", env.ErrorMessage) return nil, fmt.Errorf("Incorrect password.")
} else if status == http.StatusUnauthorized { } else if status == http.StatusNotFound {
return nil, fmt.Errorf("Incorrect password.") return nil, fmt.Errorf("User does not exist.")
} else if status == http.StatusNotFound { } else if status == http.StatusTooManyRequests {
return nil, fmt.Errorf("User does not exist.") return nil, fmt.Errorf("Stop repeatedly trying to log in.")
} else if status == http.StatusTooManyRequests { }
return nil, fmt.Errorf("Stop repeatedly trying to log in.") return nil, fmt.Errorf("Problem authenticating: %d. %v\n", status, err)
} }
return nil, fmt.Errorf("Problem authenticating: %d. %v\n", status, err)
c.SetToken(u.AccessToken)
return u, nil
} }
// LogOut logs the current user out, making the Client's current access token // LogOut logs the current user out, making the Client's current access token