From 7bbf4628e38e1d3be8f88738d7b92de75d34d75a Mon Sep 17 00:00:00 2001 From: Sam Whited <sam@samwhited.com> Date: Fri, 25 Feb 2022 11:34:35 -0500 Subject: [PATCH] Handle error when fetching gateways Previously this error was not handled at the top level, resulting in a panic if the gateways could not be populated. This patch removes the logging when fetching the JSON as this double handles the error (it logs it and returns it to be handled again), and handles it at the top level instead where we log it an exit (keeping the same behavior as the panic but with a nice error message and no stack dump). Signed-off-by: Sam Whited <sam@samwhited.com> --- gateways.go | 1 - main.go | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gateways.go b/gateways.go index 7020b96..a72ea73 100644 --- a/gateways.go +++ b/gateways.go @@ -69,7 +69,6 @@ func (b *bonafide) getGateways() ([]gateway, error) { func (b *bonafide) fetchEipJSON() error { resp, err := b.client.Post(b.eipAPI, "", nil) if err != nil { - log.Println("Error fetching json: ", err) return err } defer resp.Body.Close() diff --git a/main.go b/main.go index 5f7a66b..b879194 100644 --- a/main.go +++ b/main.go @@ -276,7 +276,10 @@ func main() { log.Println("Seeding gateway list from " + configuredAPI) bonafide := newBonafide(configuredAPI) - bonafide.getGateways() + _, err = bonafide.getGateways() + if err != nil { + log.Fatal("Error fetching gateways:", err) + } geoipdb.geolocateGateways(bonafide) bonafide.listGateways() -- GitLab