Skip to content

Commit

Permalink
Handle connection refused errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmartin committed Dec 7, 2023
1 parent e8a25cf commit ddb5d65
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions go-trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ddb5d65

Please sign in to comment.