File: helper.go

package info (click to toggle)
gitlab-agent 16.1.3-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 6,324 kB
  • sloc: makefile: 175; sh: 52; ruby: 3
file content (35 lines) | stat: -rw-r--r-- 770 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package api

import (
	"errors"
	"net/http"

	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/gitlab"
)

// IsCacheableError checks if an error is cacheable.
func IsCacheableError(err error) bool {
	var e *gitlab.ClientError
	if !errors.As(err, &e) {
		return false // not a client error, probably a network error
	}
	switch e.StatusCode {
	case http.StatusUnauthorized, http.StatusForbidden, http.StatusNotFound:
		return true
	default:
		return false
	}
}

func joinOpts(extra []gitlab.DoOption, opts ...gitlab.DoOption) []gitlab.DoOption {
	if len(extra) == 0 {
		return opts
	}
	if len(opts) == 0 {
		return extra
	}
	res := make([]gitlab.DoOption, 0, len(extra)+len(opts))
	res = append(res, opts...)
	res = append(res, extra...)
	return res
}