Read about our upcoming Code of Conduct on this issue

Commit 18156564 authored by feistel's avatar feistel
Browse files

refactor: change httpclient to return an error

parent 8500146e19b0
......@@ -15,7 +15,6 @@
"gitlab.com/gitlab-org/gitlab-shell/client"
"gitlab.com/gitlab-org/gitlab-shell/internal/metrics"
"gitlab.com/gitlab-org/labkit/log"
)
const (
......@@ -59,6 +58,7 @@
Server ServerConfig `yaml:"sshd"`
httpClient *client.HttpClient
httpClientErr error
httpClientOnce sync.Once
}
......@@ -96,7 +96,7 @@
}
}
func (c *Config) HttpClient() *client.HttpClient {
func (c *Config) HttpClient() (*client.HttpClient, error) {
c.httpClientOnce.Do(func() {
client, err := client.NewHTTPClientWithOpts(
c.GitlabUrl,
......@@ -108,7 +108,8 @@
nil,
)
if err != nil {
log.WithError(err).Fatal("new http client with opts")
c.httpClientErr = err
return
}
tr := client.Transport
......@@ -117,7 +118,7 @@
c.httpClient = client
})
return c.httpClient
return c.httpClient, c.httpClientErr
}
// NewFromDirExternal returns a new config from a given root dir. It also applies defaults appropriate for
......
......@@ -29,5 +29,6 @@
url := testserver.StartHttpServer(t, []testserver.TestRequestHandler{})
config := &Config{GitlabUrl: url}
client := config.HttpClient()
client, err := config.HttpClient()
require.NoError(t, err)
......@@ -33,5 +34,5 @@
_, err := client.Get("http://host.com/path")
_, err = client.Get("http://host.com/path")
require.NoError(t, err)
ms, err := prometheus.DefaultGatherer.Gather()
......
......@@ -15,7 +15,10 @@
)
func GetClient(config *config.Config) (*client.GitlabNetClient, error) {
httpClient := config.HttpClient()
httpClient, err := config.HttpClient()
if err != nil {
return nil, err
}
if httpClient == nil {
return nil, fmt.Errorf("Unsupported protocol")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment