From 6cb9da575962182d2fe6fd05098e3f9a0bf80c90 Mon Sep 17 00:00:00 2001 From: Arunesh Dwivedi Date: Sun, 28 Jun 2026 15:13:15 +0530 Subject: [PATCH] fix(http): return early on request errors to prevent nil pointer panic RequestWithHeaders continued executing after http.NewRequest and http.DefaultClient.Do errors, dereferencing nil response and causing controller panics when external APIs drop connections. Signed-off-by: Arunesh Dwivedi --- pkg/http/httpClient.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/http/httpClient.go b/pkg/http/httpClient.go index 1ae626ce..0c843060 100644 --- a/pkg/http/httpClient.go +++ b/pkg/http/httpClient.go @@ -41,6 +41,10 @@ func (client *HttpClient) RequestWithHeaders(requestType string, body []byte, he log.Error(err, "Failed to craft HTTP Request. METHOD: "+requestType+ " URL: "+client.url+ " PAYLOAD: "+string(body)) + return HttpResponse{ + StatusCode: http.StatusInternalServerError, + Header: make(http.Header), + } } if headers != nil { @@ -50,8 +54,16 @@ func (client *HttpClient) RequestWithHeaders(requestType string, body []byte, he response, err := http.DefaultClient.Do(request) if err != nil { log.Error(err, "") + return HttpResponse{ + StatusCode: http.StatusInternalServerError, + Header: make(http.Header), + } } else if response == nil { log.Error(nil, "got empty response") + return HttpResponse{ + StatusCode: http.StatusInternalServerError, + Header: make(http.Header), + } } httpResponse := HttpResponse{