Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: fixes issue with printing empty body #362 #363

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions internal/apiclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,18 @@ func HttpClient(params ...string) (respBody []byte, err error) {
case 1:
req, err = http.NewRequest(http.MethodGet, params[0], nil)
case 2:
payload, _ := PrettifyJSON([]byte(params[1]))
clilog.Debug.Println("Payload: ", string(payload))
payload := []byte(params[1])
if len(payload) > 0 {
//attempt to convert to json
jsonPayload, err := PrettifyJSON([]byte(params[1]))
if err != nil {
//payload is not json, print as-is
clilog.Debug.Println("Payload: ", string(payload))
} else {
//print json
clilog.Debug.Println("Payload: ", string(jsonPayload))
}
}
req, err = http.NewRequest(http.MethodPost, params[0], bytes.NewBuffer([]byte(params[1])))
case 3:
if req, err = getRequest(params); err != nil {
Expand Down Expand Up @@ -346,7 +356,7 @@ func PrettifyJSON(body []byte) ([]byte, error) {
var prettyJSON bytes.Buffer
err := json.Indent(&prettyJSON, body, "", "\t")
if err != nil {
clilog.Error.Println("error parsing response: ", err)
//fail silently
return nil, err
}
return prettyJSON.Bytes(), nil
Expand Down