Skip to content

Commit

Permalink
zedcloud: print http response content on error
Browse files Browse the repository at this point in the history
print the http body for responses from zedcloud;
this is helpful for debugging and instructing the user on how to fix
an encountered error.

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
  • Loading branch information
christoph-zededa committed Jan 30, 2023
1 parent ba96f47 commit 1755fe6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/pillar/zedcloud/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -939,9 +940,18 @@ func SendOnIntf(workContext context.Context, ctx *ZedCloudContext, destURL strin
rv.RespContents = contents
return rv, nil
default:
errStr := fmt.Sprintf("SendOnIntf to %s reqlen %d statuscode %d %s",
maxlen := 256
if maxlen > len(contents) {
maxlen = len(contents)
}

hexdump := hex.Dump(bytes.TrimSpace(contents[:maxlen]))
// remove trailing newline from hex.Dump
hexdump = strings.TrimSuffix(hexdump, "\n")

errStr := fmt.Sprintf("SendOnIntf to %s reqlen %d statuscode %d %s body:\n%s",
reqUrl, reqlen, resp.StatusCode,
http.StatusText(resp.StatusCode))
http.StatusText(resp.StatusCode), hexdump)
// zedrouter probing sends 'http' to zedcloud server, expect to get status of 404, not an error
if resp.StatusCode != http.StatusNotFound || ctx.AgentName != "zedrouter" {
log.Errorln(errStr)
Expand Down

0 comments on commit 1755fe6

Please sign in to comment.