diff --git a/internal/config/config.go b/internal/config/config.go index 901562420e61fe3950886bebba7ff094eb8c91b6..31aeb4f06f7c8b9063579d9232310ac3a99befe0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -806,21 +806,21 @@ func (c *ProviderConfig) TestConnection(resolver VariableResolver) error { for k, v := range c.ExtraHeaders { req.Header.Set(k, v) } - b, err := client.Do(req) + resp, err := client.Do(req) if err != nil { return fmt.Errorf("failed to create request for provider %s: %w", c.ID, err) } + defer resp.Body.Close() if c.ID == string(catwalk.InferenceProviderZAI) { - if b.StatusCode == http.StatusUnauthorized { - // for z.ai just check if the http response is not 401 - return fmt.Errorf("failed to connect to provider %s: %s", c.ID, b.Status) + if resp.StatusCode == http.StatusUnauthorized { + // For z.ai just check if the http response is not 401. + return fmt.Errorf("failed to connect to provider %s: %s", c.ID, resp.Status) } } else { - if b.StatusCode != http.StatusOK { - return fmt.Errorf("failed to connect to provider %s: %s", c.ID, b.Status) + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("failed to connect to provider %s: %s", c.ID, resp.Status) } } - _ = b.Body.Close() return nil }