Skip to content

Commit

Permalink
detect offline for more valid errors
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Dec 26, 2023
1 parent f86f90f commit 6d5d335
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"crypto/md5"
fipssha256 "crypto/sha256"
"crypto/tls"
"encoding/base64"
"encoding/hex"
"encoding/xml"
Expand Down Expand Up @@ -622,7 +623,7 @@ func IsNetworkOrHostDown(err error, expectTimeouts bool) bool {
urlErr := &url.Error{}
if errors.As(err, &urlErr) {
switch urlErr.Err.(type) {
case *net.DNSError, *net.OpError, net.UnknownNetworkError:
case *net.DNSError, *net.OpError, net.UnknownNetworkError, *tls.CertificateVerificationError:

Check failure on line 626 in utils.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and windows-latest

undefined: tls.CertificateVerificationError

Check failure on line 626 in utils.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

undefined: tls.CertificateVerificationError (typecheck)
return true
}
}
Expand All @@ -649,7 +650,12 @@ func IsNetworkOrHostDown(err error, expectTimeouts bool) bool {
case strings.Contains(err.Error(), "connection refused"):
// If err is connection refused
return true

case strings.Contains(err.Error(), "server gave HTTP response to HTTPS client"):
// If err is TLS client is used with HTTP server
return true
case strings.Contains(err.Error(), "Client sent an HTTP request to an HTTPS server"):
// If err is plain-text Client is used with a HTTPS server
return true
case strings.Contains(strings.ToLower(err.Error()), "503 service unavailable"):
// Denial errors
return true
Expand Down

0 comments on commit 6d5d335

Please sign in to comment.