@@ -54,10 +54,10 @@ var (
5454
5555// replaceCustomData replaces the custom channel data hex string with the
5656// decoded custom channel data in the JSON response.
57- func replaceCustomData (jsonBytes []byte ) ( []byte , error ) {
57+ func replaceCustomData (jsonBytes []byte ) []byte {
5858 // If there's nothing to replace, return the original JSON.
5959 if ! customDataPattern .Match (jsonBytes ) {
60- return jsonBytes , nil
60+ return jsonBytes
6161 }
6262
6363 replacedBytes := customDataPattern .ReplaceAllFunc (
@@ -78,10 +78,12 @@ func replaceCustomData(jsonBytes []byte) ([]byte, error) {
7878 var buf bytes.Buffer
7979 err := json .Indent (& buf , replacedBytes , "" , " " )
8080 if err != nil {
81- return nil , err
81+ // If we can't indent the JSON, it likely means the replacement
82+ // data wasn't correct, so we return the original JSON.
83+ return jsonBytes
8284 }
8385
84- return buf .Bytes (), nil
86+ return buf .Bytes ()
8587}
8688
8789func getContext () context.Context {
@@ -118,11 +120,7 @@ func printRespJSON(resp proto.Message) {
118120 return
119121 }
120122
121- jsonBytesReplaced , err := replaceCustomData (jsonBytes )
122- if err != nil {
123- fmt .Println ("unable to replace custom data: " , err )
124- jsonBytesReplaced = jsonBytes
125- }
123+ jsonBytesReplaced := replaceCustomData (jsonBytes )
126124
127125 fmt .Printf ("%s\n " , jsonBytesReplaced )
128126}
0 commit comments