uniform errors
This commit is contained in:
parent
9f39049dd6
commit
54185be835
3 changed files with 4 additions and 3 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
ErrDisabled = errors.New("user disabled")
|
||||
ErrInvalidAuth = errors.New("invalid auth")
|
||||
ErrInvalidHandler = errors.New("no such handler")
|
||||
)
|
||||
|
|
|
@ -160,7 +160,7 @@ func (a *Authenticator) TokenHandler(c echo.Context) error {
|
|||
// TODO: success
|
||||
user, err := a.getOrCreateUser(cred)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusUnauthorized, AuthError{Error: "access_denied", Description: "bad user"})
|
||||
return c.JSON(http.StatusUnauthorized, AuthError{Error: "access_denied", Description: err.Error()})
|
||||
}
|
||||
|
||||
if err := user.allowedToAuth(); err != nil {
|
||||
|
|
|
@ -27,7 +27,7 @@ type UserMetadata struct {
|
|||
|
||||
func (u *User) allowedToAuth() error {
|
||||
if !u.Active {
|
||||
return errors.New("user disabled")
|
||||
return ErrDisabled
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -37,7 +37,7 @@ func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) {
|
|||
log.Debug().Interface("userdata", c.user.ProviderUserData()).Msg("getOrCreateUser")
|
||||
u := a.store.User(c.UserID)
|
||||
if u == nil {
|
||||
return nil, errors.New("no such user)
|
||||
return nil, ErrInvalidAuth
|
||||
}
|
||||
|
||||
return u, nil
|
||||
|
|
Loading…
Reference in a new issue