Ks8/Folders: Fix status codes returned on create (#95055)

* Fix status codes returned by k8s folder handler
* Add test for status code when creating duplicate folder
This commit is contained in:
Arati R. authored and GitHub committed 2024-10-21 13:07:11 -03:00
1 parent 9d1f8fbdb0
commit 8abfcdbb78
3 files changed
+75 -1

No files matched your search

+24
View File
@@ -4,6 +4,9 @@ import (
"errors"
"net/http"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/util"
@@ -42,3 +45,24 @@ func ToFolderErrorResponse(err error) response.Response {
return response.ErrOrFallback(http.StatusInternalServerError, "Folder API error", err)
}
func ToFolderStatusError(err error) k8sErrors.StatusError {
resp := ToFolderErrorResponse(err)
normResp, ok := resp.(*response.NormalResponse)
if !ok {
return k8sErrors.StatusError{
ErrStatus: metav1.Status{
Message: "Folder API error",
Code: http.StatusInternalServerError,
},
}
}
return k8sErrors.StatusError{
ErrStatus: metav1.Status{
Message: normResp.ErrMessage(),
Code: int32(normResp.Status()),
},
}
}