on main help sign in
perf: fix possibly unclosed resp.body (#1818)

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

commitb8847674247c0acb21b863c57f77ca44631185ca authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateMon 12 Jan 2026, 10:22 (9 months ago) parent542750a
1 file changed+7−7
internal/config/config.go+7−7
internal/config/config.go+7−7
@@ -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