small fix
This commit is contained in:
@@ -147,27 +147,31 @@ func (o *OpenAIAPI) DoRequest(url string, params any, retries int) ([]byte, erro
|
||||
return responseBody, err
|
||||
}
|
||||
|
||||
tempData := make(map[string]any)
|
||||
var tempData any
|
||||
err = json.Unmarshal(responseBody, &tempData)
|
||||
if err != nil {
|
||||
log.Println("json unmarshal failed:", err)
|
||||
return responseBody, err
|
||||
}
|
||||
// {"error":{"message":"openai_error","type":"bad_response_status_code","param":"","code":"bad_response_status_code"}}
|
||||
if errorData, ok := tempData["error"]; ok {
|
||||
if errorPayload, ok := errorData.(map[string]any); ok {
|
||||
code := errorPayload["code"].(string)
|
||||
if code == "bad_response_status_code" {
|
||||
if retries >= 3 {
|
||||
return responseBody, BadResponseErr
|
||||
if eData, ok := tempData.(map[string]any); ok {
|
||||
if errorData, ok := eData["error"]; ok {
|
||||
if errorPayload, ok := errorData.(map[string]any); ok {
|
||||
code := errorPayload["code"].(string)
|
||||
if code == "bad_response_status_code" {
|
||||
if retries >= 3 {
|
||||
return responseBody, BadResponseErr
|
||||
}
|
||||
o.Logger.Warnln("Retrying because of bad response status code")
|
||||
return o.DoRequest(url, params, retries+1)
|
||||
}
|
||||
o.Logger.Warnln("Retrying because of bad response status code")
|
||||
return o.DoRequest(url, params, retries+1)
|
||||
return nil, errors.New(code)
|
||||
}
|
||||
return nil, errors.New(code)
|
||||
o.Logger.Errorln("Unknown error", errorData)
|
||||
return nil, errors.New(string(responseBody))
|
||||
}
|
||||
o.Logger.Errorln("Unknown error", errorData)
|
||||
return nil, errors.New(string(responseBody))
|
||||
} else if eData, ok := tempData.(string); ok {
|
||||
return responseBody, errors.New(eData)
|
||||
}
|
||||
|
||||
return responseBody, err
|
||||
|
||||
Reference in New Issue
Block a user