Documentation
¶
Overview ¶
Package errbody repairs one specific lie an upstream proxy tells: an error response whose body is not JSON, served under a JSON Content-Type.
It is shared by the Starfleet connection and the Control Plane client, which are built from generated clients that dispatch on the header and were reported against the same failure. It imports no module's generated api package — internal/clitest's layering gate holds that — so it knows nothing about how a caller classifies a status. Its job is to put the response back on the path where that can happen.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wrap ¶
func Wrap(base http.RoundTripper) http.RoundTripper
Wrap adds the repair unless base is nil.
Unlike httplog.Wrap and dryrun.Wrap there is no off switch: a mislabelled error body is equally unreadable with and without --verbose, and the bug was reported on a plain run.
Types ¶
type Transport ¶
type Transport struct {
Base http.RoundTripper
}
Transport is that repair.
Every generated Parse*Response ends in a catch-all shaped
case strings.Contains(rsp.Header.Get("Content-Type"), "json"):
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
so a mislabelled body fails INSIDE the parser, the command's `if err != nil` fires first, and CheckResponse never runs. The user got `invalid character 'N' looking for beginning of value` instead of the route-miss message (#140), for a body that was a perfectly clear `Not Found` from nginx.
On this path the relabel alone is enough: the catch-all stops matching, the raw bytes still reach the caller — Parse*Response assigns response.Body before the switch — and CheckResponse then classifies them exactly as it already does for a text/plain body.
Scope is narrow because this is a lie-detector and a false positive would swallow a real decode error:
- Error statuses only. On a 2xx an unparseable body is a genuine contract violation and must keep erroring loudly.
- JSON Content-Type only. Anything else already reaches CheckResponse.
- Bodies that are not a JSON OBJECT — see isJSONObject for why an object rather than valid JSON is the test. A well-formed error object is left alone: it parses into the generated Error type, which is what CheckResponse's discriminator reads to tell a route miss from a resource miss.