github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/bmxerror/network.go (about) 1 package bmxerror 2 3 import ( 4 "crypto/x509" 5 "fmt" 6 "net" 7 "net/url" 8 9 "golang.org/x/net/websocket" 10 ) 11 12 //WrapNetworkErrors ... 13 func WrapNetworkErrors(host string, err error) error { 14 var innerErr error 15 switch typedErr := err.(type) { 16 case *url.Error: 17 innerErr = typedErr.Err 18 case *websocket.DialError: 19 innerErr = typedErr.Err 20 } 21 22 if innerErr != nil { 23 switch typedInnerErr := innerErr.(type) { 24 case x509.UnknownAuthorityError: 25 return NewInvalidSSLCert(host, "unknown authority") 26 case x509.HostnameError: 27 return NewInvalidSSLCert(host, "not valid for the requested host") 28 case x509.CertificateInvalidError: 29 return NewInvalidSSLCert(host, "") 30 case *net.OpError: 31 if typedInnerErr.Op == "dial" { 32 return fmt.Errorf("%s\n%s", err.Error(), "TIP: If you are behind a firewall and require an HTTP proxy, verify the https_proxy environment variable is correctly set. Else, check your network connection.") 33 } 34 } 35 } 36 37 return err 38 }