From 27108460504bcd71d4f71d6294f02e0e3366a5a0 Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Thu, 14 Nov 2024 06:06:58 +0100 Subject: [PATCH] fix: check error of httpClient.Do() --- downdetector-exporter.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/downdetector-exporter.go b/downdetector-exporter.go index b21d60d..f825c39 100644 --- a/downdetector-exporter.go +++ b/downdetector-exporter.go @@ -404,6 +404,10 @@ func initToken() { } // send the token refresh request res, err := httpClient.Do(req) + if err != nil { + level.Error(lg).Log("msg", fmt.Sprintf("Couldn't get token: %s", err.Error())) + return + } if res.StatusCode != 200 { // return if we weren't successful - we have tokenGraceSeconds to retry body, _ := io.ReadAll(res.Body) @@ -454,6 +458,10 @@ func getMetrics(companyIDs string, searchString string) { } // send the metrics request res, err := httpClient.Do(req) + if err != nil { + level.Error(lg).Log("msg", fmt.Sprintf("Couldn't get metrics: %s", err.Error())) + return + } if res.StatusCode != 200 { // return if we weren't successful body, _ := io.ReadAll(res.Body) @@ -494,7 +502,7 @@ func getMetrics(companyIDs string, searchString string) { default: companySet.NumStatus = -1 } - // get last value from Stats24 array + // get last value from Stats24 array companySet.Stats15 = companySet.IgnoreStats24[len(companySet.IgnoreStats24)-1] // Debugging output