(response *github.Response, err error)
| 264 | } |
| 265 | |
| 266 | func parseError(response *github.Response, err error) error { |
| 267 | var statusCode int |
| 268 | if response != nil { |
| 269 | statusCode = response.StatusCode |
| 270 | } |
| 271 | |
| 272 | switch statusCode { |
| 273 | case http.StatusNotFound: |
| 274 | return runnerErrors.ErrNotFound |
| 275 | case http.StatusUnauthorized: |
| 276 | return runnerErrors.ErrUnauthorized |
| 277 | case http.StatusUnprocessableEntity: |
| 278 | return runnerErrors.ErrBadRequest |
| 279 | default: |
| 280 | if statusCode >= 100 && statusCode < 300 { |
| 281 | return nil |
| 282 | } |
| 283 | if err != nil { |
| 284 | errResp := &github.ErrorResponse{} |
| 285 | if errors.As(err, &errResp) && errResp.Response != nil { |
| 286 | switch errResp.Response.StatusCode { |
| 287 | case http.StatusNotFound: |
| 288 | return runnerErrors.ErrNotFound |
| 289 | case http.StatusUnauthorized: |
| 290 | return runnerErrors.ErrUnauthorized |
| 291 | case http.StatusUnprocessableEntity: |
| 292 | return runnerErrors.ErrBadRequest |
| 293 | default: |
| 294 | // ugly hack. Gitea returns 500 if we try to remove a runner that does not exist. |
| 295 | if strings.Contains(err.Error(), "does not exist") { |
| 296 | return runnerErrors.ErrNotFound |
| 297 | } |
| 298 | return err |
| 299 | } |
| 300 | } |
| 301 | return err |
| 302 | } |
| 303 | return errors.New("unknown error") |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | func (g *githubClient) RemoveEntityRunner(ctx context.Context, runnerID int64) error { |
| 308 | var response *github.Response |
no test coverage detected