fix testAllChannels nil pointer panic

This commit is contained in:
HynoR 2024-06-27 11:41:52 +08:00
parent 1117112225
commit 37a0930db4

View File

@ -222,16 +222,18 @@ func testAllChannels(notify bool) error {
if channel.AutoBan != nil && *channel.AutoBan == 0 { if channel.AutoBan != nil && *channel.AutoBan == 0 {
ban = false ban = false
} }
openAiErrWithStatus := dto.OpenAIErrorWithStatusCode{ if openaiErr != nil {
StatusCode: -1, openAiErrWithStatus := dto.OpenAIErrorWithStatusCode{
Error: *openaiErr, StatusCode: -1,
LocalError: false, Error: *openaiErr,
} LocalError: false,
if isChannelEnabled && service.ShouldDisableChannel(&openAiErrWithStatus) && ban { }
service.DisableChannel(channel.Id, channel.Name, err.Error()) if isChannelEnabled && service.ShouldDisableChannel(&openAiErrWithStatus) && ban {
} service.DisableChannel(channel.Id, channel.Name, err.Error())
if !isChannelEnabled && service.ShouldEnableChannel(err, openaiErr, channel.Status) { }
service.EnableChannel(channel.Id, channel.Name) if !isChannelEnabled && service.ShouldEnableChannel(err, openaiErr, channel.Status) {
service.EnableChannel(channel.Id, channel.Name)
}
} }
channel.UpdateResponseTime(milliseconds) channel.UpdateResponseTime(milliseconds)
time.Sleep(common.RequestInterval) time.Sleep(common.RequestInterval)