Closed
Description
When OpenAI or Azure returns an undefined error, since the JSON parsing meets the expectations of ErrorResponse, the "error, unexpected end of JSON input" error will be returned
client.go : line 134
func:handleErrorResp
err := json.NewDecoder(resp.Body).Decode(&errRes)
The real error message cannot be captured , but errRes.Error can get the real error message.
Example Azure origin response body:
{
"error":{
"code":"AccessDenied",
"message":"Access denied due to Virtual Network/Firewall rules."
}
}
Calling “response, err := client.CreateChatCompletion()” gets “error, unexpected end of JSON input”,but unable to get correct error:Access denied due to Virtual Network/Firewall rules.
I think the correct error message can be obtained by modifying it in the following way:
func (c *Client) handleErrorResp(resp *http.Response) error {
var errRes ErrorResponse
err := json.NewDecoder(resp.Body).Decode(&errRes)
if err != nil || errRes.Error == nil {
reqErr := RequestError{
HTTPStatusCode: resp.StatusCode,
Err: err,
}
if errRes.Error != nil{
reqErr.Err = errRes.Error
}
return fmt.Errorf("error, %w", &reqErr)
}
errRes.Error.HTTPStatusCode = resp.StatusCode
return fmt.Errorf("error, status code: %d, message: %w", resp.StatusCode, errRes.Error)
}
Go Version:1.19.7
go-openai Version:1.9.0