mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 07:12:20 +08:00
Chore: Handle wrapped errors (#29223)
* Chore: Handle wrapped errors Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@ -167,7 +168,7 @@ func (hs *HTTPServer) PostSyncUserWithLDAP(c *models.ReqContext) Response {
|
||||
query := models.GetUserByIdQuery{Id: userId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil { // validate the userId exists
|
||||
if err == models.ErrUserNotFound {
|
||||
if errors.Is(err, models.ErrUserNotFound) {
|
||||
return Error(404, models.ErrUserNotFound.Error(), nil)
|
||||
}
|
||||
|
||||
@ -177,7 +178,7 @@ func (hs *HTTPServer) PostSyncUserWithLDAP(c *models.ReqContext) Response {
|
||||
authModuleQuery := &models.GetAuthInfoQuery{UserId: query.Result.Id, AuthModule: models.AuthModuleLDAP}
|
||||
|
||||
if err := bus.Dispatch(authModuleQuery); err != nil { // validate the userId comes from LDAP
|
||||
if err == models.ErrUserNotFound {
|
||||
if errors.Is(err, models.ErrUserNotFound) {
|
||||
return Error(404, models.ErrUserNotFound.Error(), nil)
|
||||
}
|
||||
|
||||
@ -188,7 +189,7 @@ func (hs *HTTPServer) PostSyncUserWithLDAP(c *models.ReqContext) Response {
|
||||
user, _, err := ldapServer.User(query.Result.Login)
|
||||
|
||||
if err != nil {
|
||||
if err == multildap.ErrDidNotFindUser { // User was not in the LDAP server - we need to take action:
|
||||
if errors.Is(err, multildap.ErrDidNotFindUser) { // User was not in the LDAP server - we need to take action:
|
||||
if setting.AdminUser == query.Result.Login { // User is *the* Grafana Admin. We cannot disable it.
|
||||
errMsg := fmt.Sprintf(`Refusing to sync grafana super admin "%s" - it would be disabled`, query.Result.Login)
|
||||
logger.Error(errMsg)
|
||||
@ -197,7 +198,6 @@ func (hs *HTTPServer) PostSyncUserWithLDAP(c *models.ReqContext) Response {
|
||||
|
||||
// Since the user was not in the LDAP server. Let's disable it.
|
||||
err := login.DisableExternalUser(query.Result.Login)
|
||||
|
||||
if err != nil {
|
||||
return Error(http.StatusInternalServerError, "Failed to disable the user", err)
|
||||
}
|
||||
@ -314,7 +314,7 @@ func (hs *HTTPServer) GetUserFromLDAP(c *models.ReqContext) Response {
|
||||
cmd := &models.GetTeamsForLDAPGroupCommand{Groups: user.Groups}
|
||||
err = bus.Dispatch(cmd)
|
||||
|
||||
if err != bus.ErrHandlerNotFound && err != nil {
|
||||
if err != nil && !errors.Is(err, bus.ErrHandlerNotFound) {
|
||||
return Error(http.StatusBadRequest, "Unable to find the teams for this user", err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user