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
}
|