Skip to content

Commit

Permalink
Handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mongey committed Dec 28, 2017
1 parent aa3186f commit 250d98b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions kafka/resource_kafka_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ func topicCreate(d *schema.ResourceData, meta interface{}) error {
res, err := broker.CreateTopics(req)

if err == nil {
if len(res.TopicErrors) > 0 {
for _, e := range res.TopicErrors {
if e.Err != 0 {
return fmt.Errorf("%s", e.Err)
}
for _, e := range res.TopicErrors {
if e.Err != samara.ErrNoError {
return fmt.Errorf("%s", e.Err)
}
}
log.Printf("[INFO] Created topic %s in Kafka", t.Name)
Expand All @@ -100,9 +98,15 @@ func topicDelete(d *schema.ResourceData, meta interface{}) error {
Topics: []string{t.Name},
Timeout: 1000 * time.Millisecond,
}
_, err = broker.DeleteTopics(req)
res, err := broker.DeleteTopics(req)

if err != nil {
if err == nil {
for k, e := range res.TopicErrorCodes {
if e != samara.ErrNoError {
return fmt.Errorf("%s : %s", k, e)
}
}
} else {
log.Printf("[ERROR] Error deleting topic %s from Kafka", err)
return err
}
Expand Down

0 comments on commit 250d98b

Please sign in to comment.