diff --git a/pkg/provider/gitlab/gitlab.go b/pkg/provider/gitlab/gitlab.go index 5f5c600e3..4e1158ea7 100644 --- a/pkg/provider/gitlab/gitlab.go +++ b/pkg/provider/gitlab/gitlab.go @@ -224,14 +224,22 @@ func (g *gitlabBase) GetSecret(_ context.Context, ref esv1beta1.ExternalSecretDa data, resp, err := g.projectVariablesClient.GetVariable(g.store.ProjectID, ref.Key, vopts) metrics.ObserveAPICall(constants.ProviderGitLab, constants.CallGitLabProjectVariableGet, err) + if err != nil { + return nil, err + } + + if resp == nil { + return nil, errors.New("gitlab response is nil") + } + if !isEmptyOrWildcard(g.store.Environment) && resp.StatusCode == http.StatusNotFound { vopts.Filter.EnvironmentScope = "*" data, resp, err = g.projectVariablesClient.GetVariable(g.store.ProjectID, ref.Key, vopts) metrics.ObserveAPICall(constants.ProviderGitLab, constants.CallGitLabProjectVariableGet, err) } - if resp.StatusCode >= 400 && resp.StatusCode != http.StatusNotFound && err != nil { - return nil, err + if resp.StatusCode >= 400 && resp.StatusCode != http.StatusNotFound { + return nil, fmt.Errorf("gitlab response status code was not OK: %d", resp.StatusCode) } err = g.ResolveGroupIds()