Skip to content

Commit e87b460

Browse files
committed
fix(channel): 当没有可用密钥时返回错误而不是第一个密钥
1 parent 3dc4d6c commit e87b460

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

model/channel.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ func (channel *Channel) GetNextEnabledKey() (string, int, *types.NewAPIError) {
138138
enabledIdx = append(enabledIdx, i)
139139
}
140140
}
141-
// If no specific status list or none enabled, fall back to first key
141+
// If no specific status list or none enabled, return an explicit error so caller can
142+
// properly handle a channel with no available keys (e.g. mark channel disabled).
143+
// Returning the first key here caused requests to keep using an already-disabled key.
142144
if len(enabledIdx) == 0 {
143-
return keys[0], 0, nil
145+
return "", 0, types.NewError(errors.New("no enabled keys"), types.ErrorCodeChannelNoAvailableKey)
144146
}
145147

146148
switch channel.ChannelInfo.MultiKeyMode {

0 commit comments

Comments
 (0)