TestCallAPI_ParseJSONFailureWrapsAsAPI pins the typed-envelope contract for malformed JSON response bodies: WrapJSONResponseParseError emits *errs.InternalError{Subtype: invalid_response} with the rawAPIJSONHint preserved on Problem.Hint. Pagination / cmd/api / cmd/service callers see the typed JSON
(t *testing.T)
| 676 | // the typed JSON stderr envelope (exit 5/internal) — wire `type` is |
| 677 | // "internal". |
| 678 | func TestCallAPI_ParseJSONFailureWrapsAsAPI(t *testing.T) { |
| 679 | rt := roundTripFunc(func(_ *http.Request) (*http.Response, error) { |
| 680 | return &http.Response{ |
| 681 | StatusCode: 200, |
| 682 | Header: http.Header{"Content-Type": []string{"application/json"}}, |
| 683 | Body: io.NopCloser(strings.NewReader(`{ malformed`)), |
| 684 | }, nil |
| 685 | }) |
| 686 | ac, _ := newTestAPIClient(t, rt) |
| 687 | |
| 688 | _, err := ac.CallAPI(context.Background(), RawApiRequest{ |
| 689 | Method: "GET", |
| 690 | URL: "/open-apis/contact/v3/users/me", |
| 691 | As: "bot", |
| 692 | }) |
| 693 | |
| 694 | if err == nil { |
| 695 | t.Fatal("expected JSON parse error, got nil") |
| 696 | } |
| 697 | var intErr *errs.InternalError |
| 698 | if !errors.As(err, &intErr) { |
| 699 | t.Fatalf("expected *errs.InternalError, got %T (%v)", err, err) |
| 700 | } |
| 701 | if intErr.Category != errs.CategoryInternal { |
| 702 | t.Errorf("Category = %v, want %v", intErr.Category, errs.CategoryInternal) |
| 703 | } |
| 704 | if intErr.Subtype != errs.SubtypeInvalidResponse { |
| 705 | t.Errorf("Subtype = %v, want %v", intErr.Subtype, errs.SubtypeInvalidResponse) |
| 706 | } |
| 707 | if intErr.Hint != rawAPIJSONHint { |
| 708 | t.Errorf("Hint = %q, want rawAPIJSONHint preserved", intErr.Hint) |
| 709 | } |
| 710 | if output.ExitCodeOf(err) != output.ExitInternal { |
| 711 | t.Errorf("ExitCodeOf = %d, want %d (internal)", output.ExitCodeOf(err), output.ExitInternal) |
| 712 | } |
| 713 | } |
nothing calls this directly
no test coverage detected