mirror of
https://github.com/grafana/grafana.git
synced 2026-08-19 01:34:54 -05:00
FolderPermissions: Return 404 error when folder does not exist instead of 500 (#112919)
* AccessControl: Improve folder permissions error handling - Add proper error type handling for folder permission checks - Convert dashboards.ErrFolderNotFound to folder.ErrFolderNotFound - Preserve errutil.Error types when returned - Wrap unhandled errors with new ErrFolderUnhandledError for better error tracking * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update pkg/services/accesscontrol/ossaccesscontrol/folder.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -2,8 +2,10 @@ package ossaccesscontrol
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/errutil"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
@@ -22,6 +24,8 @@ type FolderPermissionsService struct {
|
||||
*resourcepermissions.Service
|
||||
}
|
||||
|
||||
var ErrFolderUnhandledError = errutil.Internal("folder.unhandled-error", errutil.WithPublicMessage("Unhandled folder error"))
|
||||
|
||||
var FolderViewActions = []string{dashboards.ActionFoldersRead, accesscontrol.ActionAlertingRuleRead, libraryelements.ActionLibraryPanelsRead, accesscontrol.ActionAlertingSilencesRead}
|
||||
var FolderEditActions = append(FolderViewActions, []string{
|
||||
dashboards.ActionFoldersWrite,
|
||||
@@ -106,7 +110,16 @@ func ProvideFolderPermissions(
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
switch {
|
||||
case func() bool {
|
||||
var errUtilErr errutil.Error
|
||||
return errors.As(err, &errUtilErr)
|
||||
}():
|
||||
return err
|
||||
case errors.Is(err, dashboards.ErrFolderNotFound):
|
||||
return folder.ErrFolderNotFound.Errorf("folder not found")
|
||||
}
|
||||
return ErrFolderUnhandledError.Errorf("unhandled folder error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user