mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-08 15:13:42 +08:00
feat: 状态码复写
This commit is contained in:
@@ -86,3 +86,22 @@ func RelayErrorHandler(resp *http.Response) (errWithStatusCode *dto.OpenAIErrorW
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func ResetStatusCode(openaiErr *dto.OpenAIErrorWithStatusCode, statusCodeMappingStr string) {
|
||||
if statusCodeMappingStr == "" || statusCodeMappingStr == "{}" {
|
||||
return
|
||||
}
|
||||
statusCodeMapping := make(map[string]string)
|
||||
err := json.Unmarshal([]byte(statusCodeMappingStr), &statusCodeMapping)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if openaiErr.StatusCode == http.StatusOK {
|
||||
return
|
||||
}
|
||||
codeStr := strconv.Itoa(openaiErr.StatusCode)
|
||||
if _, ok := statusCodeMapping[codeStr]; ok {
|
||||
intCode, _ := strconv.Atoi(statusCodeMapping[codeStr])
|
||||
openaiErr.StatusCode = intCode
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user