Folders: Fix error handling for zanzana (#115056)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user