[go-nuts] Re: net/http and errors.

2016-12-01 Thread mb . dhananjay
> if err, ok := err.(*url.Error); ok { > if err, ok := err.Err.(*net.OpError); ok { > if err, ok := err.Err.(*net.DNSError); ok { > fmt.Println("DNS ERROR:", err) > } > } > } > This works as expected. :-) On Monday, November 28, 2016 at 9:32:55 PM UTC+1, Dave Cheney wrote: > > Indeed. Does

[go-nuts] Re: net/http and errors.

2016-11-28 Thread Dave Cheney
Indeed. Does your program differentiate between a URL not resolving, the webserver at the other end being down or refusing to connect, or it returnining a non temporary fatal error, 4xx? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

[go-nuts] Re: net/http and errors.

2016-11-28 Thread James Bardin
If you want to assert your way down to the original error, the order of the structures returned from http.Get is: if err, ok := err.(*url.Error); ok { if err, ok := err.Err.(*net.OpError); ok { if err, ok := err.Err.(*net.DNSError); ok { fmt.Println("DNS ERROR:", err) } } } Again though, the

[go-nuts] Re: net/http and errors.

2016-11-28 Thread mb . dhananjay
I'm downloading a large number of urls and the result is expected to have failure reasons, DNS lookup failed being one. calling lookup manually would solve my issue, I suppose. Just wanted to make sure that I'm not missing any obvious solutions. 1. lookup DNS and if it succeeds, 2. try

[go-nuts] Re: net/http and errors.

2016-11-28 Thread Dave Cheney
What specifically do you want to handle about DNS errors ? If you have a set of possible dns names and you don't know if some of them are valid, you could use net.LookupHost to check which ones are valid before calling http.Get. On Monday, 28 November 2016 22:44:37 UTC+11, mb.dha...@gmail.com

[go-nuts] Re: net/http and errors.

2016-11-28 Thread mb . dhananjay
But AFIU, err.Temporary() could be true for other kind of errors that might happen, isn't that a problem if I only want to handle DNS errors? On Friday, November 25, 2016 at 6:35:59 PM UTC+1, Victor Vrantchan wrote: > > In Go, you can check if a type satisfies a particular behavior by >

[go-nuts] Re: net/http and errors.

2016-11-25 Thread Victor Vrantchan
In Go, you can check if a type satisfies a particular behavior by declaring an interface, and then checking if the type satisfies that interface. In your case, you can check if the error is `Temporrary()` or not. See this snippet as an example: https://play.golang.org/p/Ffyg61iDpB I