errbody

package
v0.5.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2026 License: PostgreSQL Imports: 5 Imported by: 0

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.

The Starfleet connection and the Control Plane client both use it, since both generated clients dispatch on that header. It imports no generated api package (internal/clitest's layering gate), so it only puts the response back where the caller's own classification runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

Wrap adds the repair unless base is nil.

Unlike httplog.Wrap and dryrun.Wrap there is no off switch: a mislabelled body is as unreadable on a plain run as a verbose one.

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 and CheckResponse never runs: nginx's plain `Not Found` surfaced as `invalid character 'N' looking for beginning of value`. Relabelling is enough, because Parse*Response assigns response.Body before the switch and CheckResponse then classifies it as any text/plain body.

Scope is narrow, since a false positive would swallow a real decode error: error statuses only (an unparseable 2xx is a contract violation and must fail loudly), a JSON Content-Type only, and only a body that is not a JSON object (see isJSONObject). A well-formed error object must still parse into Error, which CheckResponse reads to tell a route miss from a resource miss.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(
	req *http.Request,
) (*http.Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL