diff --git a/pkg/kafka/topic/validators.go b/pkg/kafka/topic/validators.go index b228cbe66..37f8c9326 100644 --- a/pkg/kafka/topic/validators.go +++ b/pkg/kafka/topic/validators.go @@ -142,7 +142,7 @@ func (v *Validator) ValidateMessageRetentionSize(val interface{}) error { // ValidateNameIsAvailable checks if a topic with the given name already exists func (v *Validator) ValidateNameIsAvailable(val interface{}) error { - name, _ := val.(string) + name := fmt.Sprintf("%v", val) conn, err := v.Connection(connection.DefaultConfigRequireMasAuth) if err != nil { @@ -154,15 +154,12 @@ func (v *Validator) ValidateNameIsAvailable(val interface{}) error { return err } - _, httpRes, err := api.TopicsApi.GetTopic(context.Background(), name).Execute() - defer httpRes.Body.Close() - if err != nil { - return err - } + _, httpRes, _ := api.TopicsApi.GetTopic(context.Background(), name).Execute() if httpRes != nil && httpRes.StatusCode == http.StatusOK { return errors.New(v.Localizer.MustLocalize("kafka.topic.create.error.conflictError", localize.NewEntry("TopicName", name), localize.NewEntry("InstanceName", kafkaInstance.GetName()))) } + defer httpRes.Body.Close() return nil }