Folders: Fix error handling for zanzana (#115056)

This commit is contained in:
Stephanie Hingtgen
2025-12-10 11:45:22 +03:00
committed by GitHub
parent d1761606fb
commit 4fd03bc05e
2 changed files with 79 additions and 2 deletions
+18 -1
View File
@@ -57,7 +57,11 @@ func ToFolderErrorResponse(err error) response.Response {
// --- Kubernetes status errors ---
var statusErr *k8sErrors.StatusError
if errors.As(err, &statusErr) {
return response.Error(int(statusErr.ErrStatus.Code), statusErr.ErrStatus.Message, err)
message := statusErr.ErrStatus.Message
if message == "" {
message = getDefaultMessageForStatus(int(statusErr.ErrStatus.Code))
}
return response.Error(int(statusErr.ErrStatus.Code), message, err)
}
return response.ErrOrFallback(http.StatusInternalServerError, fmt.Sprintf("Folder API error: %s", err.Error()), err)
@@ -100,6 +104,19 @@ func ToFolderStatusError(err error) k8sErrors.StatusError {
}
}
func getDefaultMessageForStatus(statusCode int) string {
switch statusCode {
case http.StatusForbidden:
return "Access denied"
case http.StatusNotFound:
return "Folder not found"
case http.StatusBadRequest:
return "Invalid request"
default:
return "Folder API error"
}
}
func IsForbidden(err error) bool {
return k8sErrors.IsForbidden(err) || errors.Is(err, dashboards.ErrFolderAccessDenied)
}