Przeglądaj źródła

Merge pull request #2188 from QuantumNous/fix-multikey-autodisable

fix(channel): 当没有可用密钥时返回错误而不是第一个密钥
Seefs 4 miesięcy temu
rodzic
commit
43ee7a98b4
1 zmienionych plików z 4 dodań i 2 usunięć
  1. 4 2
      model/channel.go

+ 4 - 2
model/channel.go

@@ -138,9 +138,11 @@ func (channel *Channel) GetNextEnabledKey() (string, int, *types.NewAPIError) {
 			enabledIdx = append(enabledIdx, i)
 		}
 	}
-	// If no specific status list or none enabled, fall back to first key
+	// If no specific status list or none enabled, return an explicit error so caller can
+	// properly handle a channel with no available keys (e.g. mark channel disabled).
+	// Returning the first key here caused requests to keep using an already-disabled key.
 	if len(enabledIdx) == 0 {
-		return keys[0], 0, nil
+		return "", 0, types.NewError(errors.New("no enabled keys"), types.ErrorCodeChannelNoAvailableKey)
 	}
 
 	switch channel.ChannelInfo.MultiKeyMode {