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 
> 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://I don't 
> thinplay.golang.org/p/Ffyg61iDpB <https://play.golang.org/p/Ffyg61iDpB>
>
> I recommend 
> https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
>  
> and.or the GopherCon talk https://www.youtube.com/watch?v=lsBF58Q-DnY by 
> Dave Cheney for a more in-depth presentation of this idea. 
>
> On Friday, November 25, 2016 at 12:00:06 PM UTC-5, mb.dha...@gmail.com 
> wrote:
>>
>> This is a question about the net/http API, Googling was not very helpful.
>>
>>     _, err := http.Get("https://random_non_existing_domain.com";)
>>
>>
>> Following code will obviously fail, but how can I check if it failed 
>> because of DNS error not because a billion other things that might have 
>> gone wrong?
>>
>> I tried this, (mostly as a shot in the dark)
>>
>>         if e, ok := err.(net.Error); ok {
>>             fmt.Println("dial error", e.Temporary())
>>         }
>>         if e, ok := err.(*net.AddrError); ok {
>>             fmt.Println("addr rror", e.Temporary())
>>         }
>>         if e, ok := err.(*net.DNSError); ok {
>>             fmt.Println(e)
>>
>> and it seems to print 
>>
>>        dial error false
>>
>> Is there any easy way to do what I'm trying to achieve?
>>
>> -
>> dbalan
>> @notmycommit
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to