Skip to content

Commit 7e3797d

Browse files
authored
fix: 放宽验证Key的错误状态码为2XX (#107)
1 parent 2be2ea6 commit 7e3797d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

internal/channel/anthropic_channel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func (ch *AnthropicChannel) ValidateKey(ctx context.Context, key string) (bool,
115115
}
116116
defer resp.Body.Close()
117117

118-
// A 200 OK status code indicates the key is valid and can make requests.
119-
if resp.StatusCode == http.StatusOK {
118+
// Any 2xx status code indicates the key is valid.
119+
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
120120
return true, nil
121121
}
122122

internal/channel/gemini_channel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ func (ch *GeminiChannel) ValidateKey(ctx context.Context, key string) (bool, err
132132
}
133133
defer resp.Body.Close()
134134

135-
// A 200 OK status code indicates the key is valid.
136-
if resp.StatusCode == http.StatusOK {
135+
// Any 2xx status code indicates the key is valid.
136+
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
137137
return true, nil
138138
}
139139

internal/channel/openai_channel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ func (ch *OpenAIChannel) ValidateKey(ctx context.Context, key string) (bool, err
113113
}
114114
defer resp.Body.Close()
115115

116-
// A 200 OK status code indicates the key is valid and can make requests.
117-
if resp.StatusCode == http.StatusOK {
116+
// Any 2xx status code indicates the key is valid.
117+
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
118118
return true, nil
119119
}
120120

0 commit comments

Comments
 (0)