Skip to content

Commit

Permalink
Cleanup JSON output of custom request bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
erikostien-pingidentity committed Sep 27, 2024
1 parent 076784e commit 8c0e5f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions internal/commands/request/request_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ func runInternalPingOneRequest(uri string) (err error) {

if res.StatusCode < 200 || res.StatusCode >= 300 {
output.Print(output.Opts{
Message: "Custom request failed.",
Message: "Custom request",
Result: output.ENUM_RESULT_FAILURE,
Fields: map[string]any{
"response": string(body),
"response": json.RawMessage(body),
"status": res.StatusCode,
},
})
} else {
output.Print(output.Opts{
Message: "Custom request successful.",
Message: "Custom request",
Result: output.ENUM_RESULT_SUCCESS,
Fields: map[string]any{
"response": string(body),
"response": json.RawMessage(body),
"status": res.StatusCode,
},
})
Expand Down
11 changes: 9 additions & 2 deletions internal/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ func printText(opts Opts) {
if opts.Fields != nil {
fmt.Println(cyan("Additional Information:"))
for k, v := range opts.Fields {
fmt.Println(cyan("%s: %v", k, v))
l.Info().Msgf("%s: %v", k, v)
switch typedValue := v.(type) {
// If the value is a json.RawMessage, print it as a string
case json.RawMessage:
fmt.Println(cyan("%s: %s", k, typedValue))
l.Info().Msgf("%s: %s", k, typedValue)
default:
fmt.Println(cyan("%s: %v", k, v))
l.Info().Msgf("%s: %v", k, v)
}
}
}

Expand Down

0 comments on commit 8c0e5f5

Please sign in to comment.