diff --git a/backend/internal/app/router/snippet.go b/backend/internal/app/router/snippet.go index 9cf964f9..98a09a27 100644 --- a/backend/internal/app/router/snippet.go +++ b/backend/internal/app/router/snippet.go @@ -139,11 +139,13 @@ func RemoveSnippet(c *gin.Context) { return } - err = service.Snippets(ctx, body.Cluster).Remove(body.Name, body.Namespace) - if err != nil { - logger.WithError(err).Error("failed to remove snippet") - renderError(c, http.StatusInternalServerError, err) - return + if service.Snippets(ctx, body.Cluster).Has(body.Name, body.Namespace) { + err = service.Snippets(ctx, body.Cluster).Remove(body.Name, body.Namespace) + if err != nil { + logger.WithError(err).Error("failed to remove snippet") + renderError(c, http.StatusInternalServerError, err) + return + } } renderSuccess(c, http.StatusOK) diff --git a/backend/internal/app/service/snippet/manage.go b/backend/internal/app/service/snippet/manage.go index 86b0ff22..89f13f8f 100644 --- a/backend/internal/app/service/snippet/manage.go +++ b/backend/internal/app/service/snippet/manage.go @@ -73,6 +73,11 @@ func (m *Manager) Get(name, namespace string) (*Snippet, error) { return s, err } +func (m *Manager) Has(name, namespace string) bool { + _, err := m.ks.Store.GetConfigMap(namespace, name) + return err == nil +} + func (m *Manager) Create(name, namespace, category string, values map[string]interface{}, autoImport bool) error { content, err := yaml.Marshal(values) if err != nil {