Skip to content

Commit

Permalink
Fix ConfigureIndex error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aulorbe committed Jul 12, 2024
1 parent adc7e3a commit f3939ed
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pinecone/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f3939ed

Please sign in to comment.