small fix
This commit is contained in:
@@ -94,9 +94,7 @@ func (w *DatabaseWriter) Print(level slog.LogLevel, prefix string, traceback []*
|
||||
Level: level.GetName(),
|
||||
Prefix: prefix,
|
||||
Traceback: slog.FormatFullTraceback(traceback),
|
||||
Message: strings.Join(utils.Map(messages, func(el any) string {
|
||||
return fmt.Sprintf("%v", el)
|
||||
}), "\n"),
|
||||
Message: strings.Join(utils.Map(messages, utils.AnyToString), "\n"),
|
||||
Time: t,
|
||||
TimeStamp: t.Unix(),
|
||||
}
|
||||
|
||||
@@ -147,14 +147,15 @@ 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 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" {
|
||||
@@ -169,6 +170,9 @@ func (o *OpenAIAPI) DoRequest(url string, params any, retries int) ([]byte, erro
|
||||
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