openai-go
openai-go copied to clipboard
Fix shadowed err on request config execute method
Context
The current implementation when calling RequestConfig.Execute will eventually call the handler which downstream calls the Do method on the httpClient.
This is called multiple times as we loop over the retries. In this below case, we will shadow the err. This can causes issues as we are shadowing the err from the handler.
if cfg.Request.GetBody != nil {
cfg.Request.Body, err = cfg.Request.GetBody()
if err != nil {
return err
}
}
This PR introduces a var connErr error which is set on each call of a retry. At the end, if there is an issue, we return the connErr