Return max depth folder reached instead of a generic error (#99804)

* Return max depth folder reached instead of a generic error

* Unit test error function

* Lint

* Update pkg/api/apierrors/folder.go

Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>

---------

Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>
This commit is contained in:
Leonor Oliveira
2025-01-31 14:36:20 +01:00
committed by GitHub
co-authored by Jean-Philippe Quéméner
parent 9ae5552cab
commit d699f023c2
2 changed files with 89 additions and 0 deletions
+6
View File
@@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/folder"
"github.com/grafana/grafana/pkg/util"
)
@@ -43,6 +44,11 @@ func ToFolderErrorResponse(err error) response.Response {
return response.JSON(http.StatusPreconditionFailed, util.DynMap{"status": "version-mismatch", "message": dashboards.ErrFolderVersionMismatch.Error()})
}
// folder errors are wrapped in an error util, so this is the only way of comparing errors
if err.Error() == folder.ErrMaximumDepthReached.Error() {
return response.JSON(http.StatusBadRequest, util.DynMap{"messageId": "folder.maximum-depth-reached", "message": "Maximum nested folder depth reached"})
}
return response.ErrOrFallback(http.StatusInternalServerError, "Folder API error", err)
}