Skip to content

Commit 318488e

Browse files
GoncaloGarciachungthuang
authored andcommitted
TUN-8484: Print response when QuickTunnel can't be unmarshalled
1 parent e251a21 commit 318488e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cmd/cloudflared/tunnel/quick_tunnel.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tunnel
33
import (
44
"encoding/json"
55
"fmt"
6+
"io"
67
"net/http"
78
"strings"
89
"time"
@@ -44,8 +45,17 @@ func RunQuickTunnel(sc *subcommandContext) error {
4445
}
4546
defer resp.Body.Close()
4647

48+
// This will read the entire response into memory so we can print it in case of error
49+
rsp_body, err := io.ReadAll(resp.Body)
50+
if err != nil {
51+
return errors.Wrap(err, "failed to read quick-tunnel response")
52+
}
53+
4754
var data QuickTunnelResponse
48-
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
55+
if err := json.Unmarshal(rsp_body, &data); err != nil {
56+
rsp_string := string(rsp_body)
57+
fields := map[string]interface{}{"status_code": resp.Status}
58+
sc.log.Err(err).Fields(fields).Msgf("Error unmarshaling QuickTunnel response: %s", rsp_string)
4959
return errors.Wrap(err, "failed to unmarshal quick Tunnel")
5060
}
5161

0 commit comments

Comments
 (0)