WrapJSONResponseParseError lifts a response-layer JSON parse failure into *errs.InternalError{Subtype: SubtypeInvalidResponse}. Empty body, malformed JSON, and mid-stream EOFs all collapse to this single shape.
(err error, body []byte)
| 54 | // *errs.InternalError{Subtype: SubtypeInvalidResponse}. Empty body, malformed |
| 55 | // JSON, and mid-stream EOFs all collapse to this single shape. |
| 56 | func WrapJSONResponseParseError(err error, body []byte) error { |
| 57 | if err == nil { |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | var e *errs.InternalError |
| 62 | if len(bytes.TrimSpace(body)) == 0 { |
| 63 | e = errs.NewInternalError(errs.SubtypeInvalidResponse, "API returned an empty JSON response body") |
| 64 | } else { |
| 65 | e = errs.NewInternalError(errs.SubtypeInvalidResponse, "API returned an invalid JSON response: %v", err) |
| 66 | } |
| 67 | return e.WithHint("%s", rawAPIJSONHint).WithCause(err) |
| 68 | } |
| 69 | |
| 70 | // classifyNetworkSubtype maps an error chain to one of the network subtypes, |
| 71 | // falling back to SubtypeNetworkTransport. Timeout is checked first because |