diff --git a/internal/httputil/http.go b/internal/httputil/http.go index da048bc54..e2d98623b 100644 --- a/internal/httputil/http.go +++ b/internal/httputil/http.go @@ -72,8 +72,8 @@ func PostJSON[reqtype, restype any, errtype error]( } if res.StatusCode != http.StatusOK { var errorBody errtype - if msgerr := json.NewDecoder(res.Body).Decode(&errorBody); msgerr == nil { - return fmt.Errorf("internal API: %d from %s with unparsable error body", res.StatusCode, apiURL) + if msgerr := json.NewDecoder(res.Body).Decode(&errorBody); msgerr != nil { + return fmt.Errorf("internal API: %d from %s (failed to decode error: %s)", res.StatusCode, apiURL, msgerr) } return errorBody } diff --git a/internal/httputil/internalapi.go b/internal/httputil/internalapi.go index 6626d0776..5dcc596cc 100644 --- a/internal/httputil/internalapi.go +++ b/internal/httputil/internalapi.go @@ -63,8 +63,5 @@ func CallInternalProxyAPI[req, res any, errtype error](name, url string, client defer span.Finish() var response res - if err := PostJSON[req, res, errtype](ctx, span, client, url, request, &response); err != nil { - return response, err - } - return response, nil + return response, PostJSON[req, res, errtype](ctx, span, client, url, request, &response) } diff --git a/userapi/userapi_test.go b/userapi/userapi_test.go index 40e37c5d6..31a69793b 100644 --- a/userapi/userapi_test.go +++ b/userapi/userapi_test.go @@ -117,16 +117,20 @@ func TestQueryProfile(t *testing.T) { }, } - runCases := func(testAPI api.UserInternalAPI) { + runCases := func(testAPI api.UserInternalAPI, http bool) { + mode := "monolith" + if http { + mode = "HTTP" + } for _, tc := range testCases { var gotRes api.QueryProfileResponse gotErr := testAPI.QueryProfile(context.TODO(), &tc.req, &gotRes) if tc.wantErr == nil && gotErr != nil || tc.wantErr != nil && gotErr == nil { - t.Errorf("QueryProfile error, got %s want %s", gotErr, tc.wantErr) + t.Errorf("QueryProfile %s error, got %s want %s", mode, gotErr, tc.wantErr) continue } if !reflect.DeepEqual(tc.wantRes, gotRes) { - t.Errorf("QueryProfile response got %+v want %+v", gotRes, tc.wantRes) + t.Errorf("QueryProfile %s response got %+v want %+v", mode, gotRes, tc.wantRes) } } } @@ -140,10 +144,10 @@ func TestQueryProfile(t *testing.T) { if err != nil { t.Fatalf("failed to create HTTP client") } - runCases(httpAPI) + runCases(httpAPI, true) }) t.Run("Monolith", func(t *testing.T) { - runCases(userAPI) + runCases(userAPI, false) }) }