From 37a0930db4360e3668cfa62a664f722631fc6ae7 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:41:52 +0800 Subject: [PATCH] fix testAllChannels nil pointer panic --- controller/channel-test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index 1389875..37c1876 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -222,16 +222,18 @@ func testAllChannels(notify bool) error { if channel.AutoBan != nil && *channel.AutoBan == 0 { ban = false } - openAiErrWithStatus := dto.OpenAIErrorWithStatusCode{ - StatusCode: -1, - Error: *openaiErr, - LocalError: false, - } - 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 openaiErr != nil { + openAiErrWithStatus := dto.OpenAIErrorWithStatusCode{ + StatusCode: -1, + Error: *openaiErr, + LocalError: false, + } + 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) + } } channel.UpdateResponseTime(milliseconds) time.Sleep(common.RequestInterval)