فهرست منبع

Merge pull request #335 from HynoR/fix/v1

fix testAllChannels nil pointer panic
Calcium-Ion 1 سال پیش
والد
کامیت
a9b978528e
1فایلهای تغییر یافته به همراه12 افزوده شده و 10 حذف شده
  1. 12 10
      controller/channel-test.go

+ 12 - 10
controller/channel-test.go

@@ -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{
-				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)
 			channel.UpdateResponseTime(milliseconds)
 			time.Sleep(common.RequestInterval)
 			time.Sleep(common.RequestInterval)