Skip to content

Commit fc3dec4

Browse files
committed
Change signature of NewHTTPClient to accomodate errors
1 parent c3e6fcc commit fc3dec4

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

pkg/cmd/factory/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func httpClientFunc(f *cmdutil.Factory, appVersion string) func() (*http.Client,
8282
if err != nil {
8383
return nil, err
8484
}
85-
return NewHTTPClient(io, cfg, appVersion, true), nil
85+
return NewHTTPClient(io, cfg, appVersion, true)
8686
}
8787
}
8888

pkg/cmd/factory/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type configGetter interface {
5757
}
5858

5959
// generic authenticated HTTP client for commands
60-
func NewHTTPClient(io *iostreams.IOStreams, cfg configGetter, appVersion string, setAccept bool) *http.Client {
60+
func NewHTTPClient(io *iostreams.IOStreams, cfg configGetter, appVersion string, setAccept bool) (*http.Client, error) {
6161
var opts []api.ClientOption
6262
if verbose := os.Getenv("DEBUG"); verbose != "" {
6363
logTraffic := strings.Contains(verbose, "api")
@@ -98,7 +98,7 @@ func NewHTTPClient(io *iostreams.IOStreams, cfg configGetter, appVersion string,
9898
)
9999
}
100100

101-
return api.NewHTTPClient(opts...)
101+
return api.NewHTTPClient(opts...), nil
102102
}
103103

104104
func getHost(r *http.Request) string {

pkg/cmd/factory/http_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ func TestNewHTTPClient(t *testing.T) {
135135
})
136136

137137
io, _, _, stderr := iostreams.Test()
138-
client := NewHTTPClient(io, tt.args.config, tt.args.appVersion, tt.args.setAccept)
138+
client, err := NewHTTPClient(io, tt.args.config, tt.args.appVersion, tt.args.setAccept)
139+
require.NoError(t, err)
139140

140141
req, err := http.NewRequest("GET", ts.URL, nil)
141142
req.Host = tt.host

pkg/cmd/root/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ func bareHTTPClient(f *cmdutil.Factory, version string) func() (*http.Client, er
120120
if err != nil {
121121
return nil, err
122122
}
123-
return factory.NewHTTPClient(f.IOStreams, cfg, version, false), nil
123+
return factory.NewHTTPClient(f.IOStreams, cfg, version, false)
124124
}
125125
}

0 commit comments

Comments
 (0)