Skip to content

Commit b31dca6

Browse files
authored
Merge pull request #672 from AruneshDwivedi/fix/http-client-nil-panic
fix(http): return early on request errors to prevent nil pointer panic
2 parents 2deeba1 + 6cb9da5 commit b31dca6

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎pkg/http/httpClient.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func (client *HttpClient) RequestWithHeaders(requestType string, body []byte, he
4141
log.Error(err, "Failed to craft HTTP Request. METHOD: "+requestType+
4242
" URL: "+client.url+
4343
" PAYLOAD: "+string(body))
44+
return HttpResponse{
45+
StatusCode: http.StatusInternalServerError,
46+
Header: make(http.Header),
47+
}
4448
}
4549

4650
if headers != nil {
@@ -50,8 +54,16 @@ func (client *HttpClient) RequestWithHeaders(requestType string, body []byte, he
5054
response, err := http.DefaultClient.Do(request)
5155
if err != nil {
5256
log.Error(err, "")
57+
return HttpResponse{
58+
StatusCode: http.StatusInternalServerError,
59+
Header: make(http.Header),
60+
}
5361
} else if response == nil {
5462
log.Error(nil, "got empty response")
63+
return HttpResponse{
64+
StatusCode: http.StatusInternalServerError,
65+
Header: make(http.Header),
66+
}
5567
}
5668

5769
httpResponse := HttpResponse{

0 commit comments

Comments
 (0)