Skip to content

Commit

Permalink
special case http errors if the first error is not wrapped
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Nichols <n3wscott@chainguard.dev>
  • Loading branch information
n3wscott committed Mar 24, 2022
1 parent 0b3b53d commit 55e88fc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion v2/protocol/http/protocol.go
Expand Up @@ -157,7 +157,17 @@ func (p *Protocol) Send(ctx context.Context, m binding.Message, transformers ...
buf := new(bytes.Buffer)
buf.ReadFrom(message.BodyReader)
errorStr := buf.String()
err = NewResult(res.StatusCode, "%w: %s", err, errorStr)
// If the error is not wrapped, then append the original error string.
if og, ok := err.(*Result); ok {
if len(og.Format) == 0 {
og.Format = "%s"
} else {
og.Format = og.Format + ": %s"
}
og.Args = append(og.Args, errorStr)
} else {
err = NewResult(res.StatusCode, "%w: %s", err, errorStr)
}
}
}
}
Expand Down

0 comments on commit 55e88fc

Please sign in to comment.