@@ -806,21 +806,21 @@ func (c *ProviderConfig) TestConnection(resolver VariableResolver) error {
806 for k, v := range c.ExtraHeaders {
806 for k, v := range c.ExtraHeaders {
807 req.Header.Set(k, v)
807 req.Header.Set(k, v)
809− b, err := client.Do(req)
809+ resp, err := client.Do(req)
810 if err != nil {
810 if err != nil {
811 return fmt.Errorf("failed to create request for provider %s: %w", c.ID, err)
811 return fmt.Errorf("failed to create request for provider %s: %w", c.ID, err)
813+ defer resp.Body.Close()
813 if c.ID == string(catwalk.InferenceProviderZAI) {
814 if c.ID == string(catwalk.InferenceProviderZAI) {
814− if b.StatusCode == http.StatusUnauthorized {
815+ if resp.StatusCode == http.StatusUnauthorized {
815− // for z.ai just check if the http response is not 401
816+ // 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)
817+ return fmt.Errorf("failed to connect to provider %s: %s", c.ID, resp.Status)
819− if b.StatusCode != http.StatusOK {
820+ if resp.StatusCode != http.StatusOK {
820− return fmt.Errorf("failed to connect to provider %s: %s", c.ID, b.Status)
821+ return fmt.Errorf("failed to connect to provider %s: %s", c.ID, resp.Status)
824 return nil
824 return nil