From f3939ed03aed0bbdfe2d250008cac0b651776bb2 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Fri, 12 Jul 2024 08:18:31 -0700 Subject: [PATCH] Fix ConfigureIndex error handling --- pinecone/client.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pinecone/client.go b/pinecone/client.go index 2eec8a4..c000b2b 100644 --- a/pinecone/client.go +++ b/pinecone/client.go @@ -825,19 +825,16 @@ func (c *Client) ConfigureIndex(ctx context.Context, name string, podType *strin res, err := c.restClient.ConfigureIndex(ctx, name, request) if err != nil { - return nil, handleErrorResponseBody(res, "failed to configure index: ") + return nil, err } defer res.Body.Close() - response, err := decodeIndex(res.Body) - - if err != nil { - log.Fatalf("Failed to configure index %s. Error: %v", name, err) - return nil, err + if res.StatusCode != http.StatusCreated { + return nil, handleErrorResponseBody(res, "failed to configure index: ") } - return response, nil + return decodeIndex(res.Body) } // ListCollections retrieves a list of all Collections in a Pinecone [project]. See Collection for more information. @@ -1229,6 +1226,7 @@ type errorResponseMap struct { } func handleErrorResponseBody(response *http.Response, errMsgPrefix string) error { + fmt.Println("Inside handleErrorResponseBody!, first line") resBodyBytes, err := io.ReadAll(response.Body) if err != nil { return fmt.Errorf("failed to read response body: %w", err)