Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

api: fix unreachable status err (#11423)

Bruce MacDonald92c2e8a56c7e
diff --git a/api/client.go b/api/client.go
index 9f0dba8dc..7cc2acb3d 100644
--- a/api/client.go
+++ b/api/client.go
@@ -222,10 +222,6 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f
return fmt.Errorf("unmarshal: %w", err)
}
- if errorResponse.Error != "" {
- return errors.New(errorResponse.Error)
- }
-
if response.StatusCode >= http.StatusBadRequest {
return StatusError{
StatusCode: response.StatusCode,
@@ -234,6 +230,10 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f
}
}
+ if errorResponse.Error != "" {
+ return errors.New(errorResponse.Error)
+ }
+
if err := fn(bts); err != nil {
return err
}
diff --git a/api/client_test.go b/api/client_test.go
index 2ceeec9cf..f0034e02d 100644
--- a/api/client_test.go
+++ b/api/client_test.go
@@ -89,6 +89,16 @@ func TestClientStream(t *testing.T) {
},
wantErr: "mid-stream error",
},
+ {
+ name: "http status error takes precedence over general error",
+ responses: []any{
+ testError{
+ message: "custom error message",
+ statusCode: http.StatusInternalServerError,
+ },
+ },
+ wantErr: "500",
+ },
{
name: "successful stream completion",
responses: []any{