Add openai response error handling
This commit is contained in:
parent
1b9a8f319c
commit
bdaf6204f6
@ -166,7 +166,14 @@ func (c *OpenAIClient) sendRequest(ctx context.Context, req *http.Request) (*htt
|
||||
req.Header.Set("Authorization", "Bearer "+c.APIKey)
|
||||
|
||||
client := &http.Client{}
|
||||
return client.Do(req.WithContext(ctx))
|
||||
resp, err := client.Do(req.WithContext(ctx))
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
bytes, _ := io.ReadAll(resp.Body)
|
||||
return resp, fmt.Errorf("%v", string(bytes))
|
||||
}
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *OpenAIClient) CreateChatCompletion(
|
||||
|
Loading…
Reference in New Issue
Block a user