Skip to content

Commit 52b9bbe

Browse files
author
Enda
authored
fix(topic): log response body (#483)
1 parent 9006d90 commit 52b9bbe

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

pkg/cmd/kafka/topic/create/create.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"io/ioutil"
89

910
"github.com/AlecAivazis/survey/v2"
1011
"github.com/bf2fc6cc711aee1a0c2a/cli/internal/localizer"
@@ -161,6 +162,12 @@ func runCmd(opts *Options) error {
161162
createTopicReq = createTopicReq.NewTopicInput(topicInput)
162163

163164
response, httpRes, topicErr := createTopicReq.Execute()
165+
bodyBytes, err := ioutil.ReadAll(httpRes.Body)
166+
if err != nil {
167+
logger.Debug("Couls not read response body")
168+
} else {
169+
logger.Debug("Response Body:", string(bodyBytes))
170+
}
164171
if topicErr.Error() != "" {
165172
if httpRes == nil {
166173
return topicErr

pkg/cmd/kafka/topic/delete/delete.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io/ioutil"
78

89
"github.com/bf2fc6cc711aee1a0c2a/cli/internal/localizer"
910

@@ -124,6 +125,12 @@ func runCmd(opts *Options) error {
124125
// perform delete topic API request
125126
_, httpRes, topicErr := api.GetTopic(context.Background(), opts.topicName).
126127
Execute()
128+
bodyBytes, err := ioutil.ReadAll(httpRes.Body)
129+
if err != nil {
130+
logger.Debug("Could not read response body")
131+
} else {
132+
logger.Debug("Response Body:", string(bodyBytes))
133+
}
127134

128135
if topicErr.Error() != "" {
129136
if httpRes == nil {

pkg/cmd/kafka/topic/describe/describe.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"io/ioutil"
89

910
"github.com/bf2fc6cc711aee1a0c2a/cli/internal/localizer"
1011
"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmdutil"
@@ -117,10 +118,21 @@ func runCmd(opts *Options) error {
117118
return err
118119
}
119120

121+
logger, err := opts.Logger()
122+
if err != nil {
123+
return err
124+
}
125+
120126
// fetch the topic
121127
topicResponse, httpRes, topicErr := api.
122128
GetTopic(context.Background(), opts.topicName).
123129
Execute()
130+
bodyBytes, err := ioutil.ReadAll(httpRes.Body)
131+
if err != nil {
132+
logger.Debug("Could not read response body")
133+
} else {
134+
logger.Debug("Response Body:", string(bodyBytes))
135+
}
124136

125137
if topicErr.Error() != "" {
126138
if httpRes == nil {

pkg/cmd/kafka/topic/list/list.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"io/ioutil"
89

910
"github.com/bf2fc6cc711aee1a0c2a/cli/internal/localizer"
1011
"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmd/flag"
@@ -101,6 +102,12 @@ func runCmd(opts *Options) error {
101102

102103
a := api.GetTopicsList(context.Background())
103104
topicData, httpRes, topicErr := a.Execute()
105+
bodyBytes, err := ioutil.ReadAll(httpRes.Body)
106+
if err != nil {
107+
logger.Debug("Couls not read response body")
108+
} else {
109+
logger.Debug("Response Body:", string(bodyBytes))
110+
}
104111

105112
if topicErr.Error() != "" {
106113
if httpRes == nil {

pkg/cmd/kafka/topic/update/update.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"io/ioutil"
89

910
"github.com/AlecAivazis/survey/v2"
1011
"github.com/bf2fc6cc711aee1a0c2a/cli/internal/localizer"
@@ -263,6 +264,12 @@ func runCmd(opts *Options) error {
263264

264265
// update the topic
265266
response, httpRes, topicErr := updateTopicReq.Execute()
267+
bodyBytes, err := ioutil.ReadAll(httpRes.Body)
268+
if err != nil {
269+
logger.Debug("Could not read response body")
270+
} else {
271+
logger.Debug("Response Body:", string(bodyBytes))
272+
}
266273
// handle error
267274
if topicErr.Error() != "" {
268275
if httpRes == nil {

0 commit comments

Comments
 (0)