Skip to content

Commit ab0bce5

Browse files
committed
TUN-8484: Print response when QuickTunnel can't be unmarshalled
1 parent d6b0833 commit ab0bce5

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"
@@ -47,8 +48,17 @@ func RunQuickTunnel(sc *subcommandContext) error {
4748
}
4849
defer resp.Body.Close()
4950

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

0 commit comments

Comments
 (0)