@@ -806,21 +806,21 @@ func (c *ProviderConfig) TestConnection(resolver VariableResolver) error {
806806 for k, v := range c.ExtraHeaders {
807807 req.Header.Set(k, v)
808808 }
809− b, err := client.Do(req)
809+ resp, err := client.Do(req)
810810 if err != nil {
811811 return fmt.Errorf("failed to create request for provider %s: %w", c.ID, err)
812812 }
813+ defer resp.Body.Close()
813814 if c.ID == string(catwalk.InferenceProviderZAI) {
814− if b.StatusCode == http.StatusUnauthorized {
815− // for z.ai just check if the http response is not 401
816− return fmt.Errorf("failed to connect to provider %s: %s", c.ID, b.Status)
815+ if resp.StatusCode == http.StatusUnauthorized {
816+ // For z.ai just check if the http response is not 401.
817+ return fmt.Errorf("failed to connect to provider %s: %s", c.ID, resp.Status)
817818 }
818819 } else {
819− if b.StatusCode != http.StatusOK {
820− return fmt.Errorf("failed to connect to provider %s: %s", c.ID, b.Status)
820+ if resp.StatusCode != http.StatusOK {
821+ return fmt.Errorf("failed to connect to provider %s: %s", c.ID, resp.Status)
821822 }
822823 }
823− _ = b.Body.Close()
824824 return nil
825825}
826826