(req *http.Request)
| 82 | } |
| 83 | |
| 84 | func (s *ScaleSetClient) Do(req *http.Request) (*http.Response, error) { |
| 85 | if s.httpClient == nil { |
| 86 | return nil, fmt.Errorf("http client is not initialized") |
| 87 | } |
| 88 | |
| 89 | resp, err := s.httpClient.Do(req) //nolint:gosec // G704 - URL is constructed from GitHub API endpoints |
| 90 | if err != nil { |
| 91 | return nil, fmt.Errorf("failed to dispatch HTTP request: %w", err) |
| 92 | } |
| 93 | |
| 94 | if resp.StatusCode >= 200 && resp.StatusCode < 300 { |
| 95 | return resp, nil |
| 96 | } |
| 97 | |
| 98 | var body []byte |
| 99 | if resp != nil { |
| 100 | defer resp.Body.Close() |
| 101 | body, err = io.ReadAll(resp.Body) |
| 102 | if err != nil { |
| 103 | return nil, fmt.Errorf("failed to read body: %w", err) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | switch resp.StatusCode { |
| 108 | case 404: |
| 109 | return nil, runnerErrors.NewNotFoundError("resource %s not found: %q", req.URL.String(), string(body)) |
| 110 | case 400: |
| 111 | return nil, runnerErrors.NewBadRequestError("bad request while calling %s: %q", req.URL.String(), string(body)) |
| 112 | case 409: |
| 113 | return nil, runnerErrors.NewConflictError("conflict while calling %s: %q", req.URL.String(), string(body)) |
| 114 | case 401, 403: |
| 115 | return nil, runnerErrors.ErrUnauthorized |
| 116 | default: |
| 117 | return nil, fmt.Errorf("request to %s failed with status code %d: %q", req.URL.String(), resp.StatusCode, string(body)) |
| 118 | } |
| 119 | } |
no test coverage detected