Skip to content

Commit

Permalink
TUN-8484: Print response when QuickTunnel can't be unmarshalled
Browse files Browse the repository at this point in the history
  • Loading branch information
GoncaloGarcia committed Sep 3, 2024
1 parent d6b0833 commit ab0bce5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/cloudflared/tunnel/quick_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tunnel
import (
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -47,8 +48,17 @@ func RunQuickTunnel(sc *subcommandContext) error {
}
defer resp.Body.Close()

// This will read the entire response into memory so we can print it in case of error
rsp_body, err := io.ReadAll(resp.Body)
if err != nil {
return errors.Wrap(err, "failed to read quick-tunnel response")
}

var data QuickTunnelResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
if err := json.Unmarshal(rsp_body, &data); err != nil {
rsp_string := string(rsp_body)
fields := map[string]interface{}{"status_code": resp.Status}
sc.log.Err(err).Fields(fields).Msgf("Error unmarshaling QuickTunnel response: %s", rsp_string)
return errors.Wrap(err, "failed to unmarshal quick Tunnel")
}

Expand Down

0 comments on commit ab0bce5

Please sign in to comment.