diff --git a/storage/remote/client.go b/storage/remote/client.go index f00b3e7331..af696336bd 100644 --- a/storage/remote/client.go +++ b/storage/remote/client.go @@ -384,7 +384,8 @@ func (c *Client) Read(ctx context.Context, query *prompb.Query, sortSeries bool) _ = httpResp.Body.Close() cancel() - return nil, fmt.Errorf("remote server %s returned http status %s: %s", c.urlString, httpResp.Status, string(body)) + err := errors.New(string(body)) + return nil, fmt.Errorf("remote server %s returned http status %s: %w", c.urlString, httpResp.Status, err) } contentType := httpResp.Header.Get("Content-Type") diff --git a/storage/remote/client_test.go b/storage/remote/client_test.go index 112e96d2b6..27a322c39f 100644 --- a/storage/remote/client_test.go +++ b/storage/remote/client_test.go @@ -225,6 +225,7 @@ func TestReadClient(t *testing.T) { expectedSamples [][]model.SamplePair expectedErrorContains string sortSeries bool + unwrap bool }{ { name: "sorted sampled response", @@ -336,6 +337,14 @@ func TestReadClient(t *testing.T) { timeout: 5 * time.Millisecond, expectedErrorContains: "context deadline exceeded: request timed out after 5ms", }, + { + name: "unwrap error", + httpHandler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + http.Error(w, "test error", http.StatusBadRequest) + }), + expectedErrorContains: "test error\n", + unwrap: true, + }, } for _, test := range tests { @@ -366,6 +375,10 @@ func TestReadClient(t *testing.T) { ss, err := c.Read(context.Background(), query, test.sortSeries) if test.expectedErrorContains != "" { require.ErrorContains(t, err, test.expectedErrorContains) + if test.unwrap { + err = errors.Unwrap(err) + require.EqualError(t, err, test.expectedErrorContains) + } return }