Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit update/create user/role errors for clarity #4983

Merged
merged 1 commit into from Apr 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions db/users.go
@@ -1,6 +1,7 @@
package db

import (
"fmt"
"net/http"

"github.com/couchbase/sync_gateway/auth"
Expand Down Expand Up @@ -109,7 +110,7 @@ func (dbc *DatabaseContext) UpdatePrincipal(newInfo PrincipalConfig, isUser bool
if isUser {
isValid, reason := newInfo.IsPasswordValid(dbc.AllowEmptyPassword)
if !isValid {
err = base.HTTPErrorf(http.StatusBadRequest, reason)
err = base.HTTPErrorf(http.StatusBadRequest, "Error creating user: %s", reason)
return replaced, err
}
user, err = authenticator.NewUser(*newInfo.Name, "", nil)
Expand All @@ -118,7 +119,7 @@ func (dbc *DatabaseContext) UpdatePrincipal(newInfo PrincipalConfig, isUser bool
princ, err = authenticator.NewRole(*newInfo.Name, nil)
}
if err != nil {
return replaced, err
return replaced, fmt.Errorf("Error creating user/role: %w", err)
}
changed = true
} else if !allowReplace {
Expand All @@ -127,7 +128,7 @@ func (dbc *DatabaseContext) UpdatePrincipal(newInfo PrincipalConfig, isUser bool
} else if isUser && newInfo.Password != nil {
isValid, reason := newInfo.IsPasswordValid(dbc.AllowEmptyPassword)
if !isValid {
err = base.HTTPErrorf(http.StatusBadRequest, reason)
err = base.HTTPErrorf(http.StatusBadRequest, "Error updating user/role: %s", reason)
return replaced, err
}
}
Expand Down