From ddb5d65e931e19a5baed01d6c8a5d0041c251e1c Mon Sep 17 00:00:00 2001 From: jdmartin Date: Thu, 7 Dec 2023 10:31:11 -0800 Subject: [PATCH] Handle connection refused errors. --- go-trace.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/go-trace.go b/go-trace.go index 3004079..0f7966a 100644 --- a/go-trace.go +++ b/go-trace.go @@ -258,6 +258,11 @@ func doCloudFlareError() { os.Exit(0) } +func doConnectionRefusedError() { + fmt.Println("\nThe connection was refused (possibly because of DNS). Sorry!") + os.Exit(0) +} + func doTimeout() { fmt.Println("\nThe request timed out. Sorry!") os.Exit(0) @@ -307,6 +312,11 @@ func followRedirects(urlStr string) (string, []Hop, bool, error) { resp, err := client.Do(req) if err != nil { + if strings.Contains(err.Error(), "connection refused") { + doConnectionRefusedError() + return "", nil, cloudflareStatus, nil + } + if err, ok := err.(*url.Error); ok && err.Timeout() { doTimeout() return "", nil, cloudflareStatus, nil