1
0
mirror of https://github.com/writeas/go-writeas.git synced 2025-07-27 23:19:36 +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

10
auth.go
View File

@ -28,10 +28,8 @@ 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
} else if status == http.StatusBadRequest {
return nil, fmt.Errorf("Bad request: %s", env.ErrorMessage) return nil, fmt.Errorf("Bad request: %s", env.ErrorMessage)
} else if status == http.StatusUnauthorized { } else if status == http.StatusUnauthorized {
return nil, fmt.Errorf("Incorrect password.") return nil, fmt.Errorf("Incorrect password.")
@ -43,6 +41,10 @@ func (c *Client) LogIn(username, pass string) (*AuthUser, error) {
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
// invalid. // invalid.
func (c *Client) LogOut() error { func (c *Client) LogOut() error {