DNSError not recognized with HTTP Package installed



          response = HTTP.request(
              ["Content-Type" => "application/json"]; 
          println(string("dummy_method() response ", response.status))
          return JSON3.read(response.body)

catch e
        println("Error occurred: $e")
        if e isa(DNSError)
            println("Encountered a DNSError in Julia. Check your internet connection " *
                " and/or make sure you have a valid url")


I’m trying to make a GET request to an intentionally invalid API URL address and I’m receiving some error output that looks like so:

Error occurred: DNSError: invalid-url.com.au, unknown node or service (EAI_NONAME)
ERROR: UndefVarError: DNSError not defined 

I’m wondering why DNSError is not defined when I try to catch it, especially given that when I print the error message it says DNSError so I haven’t pulled the name out of nowhere when I try to catch it. For clarification, when I pass a valid URL for the HTTP.request() call, my program works just fine.

Is DNSError a part of the HTTP package? If so, why does it say that DNSError is not recognized when I have the HTTP package installed and am able to run it fine with valid URL’s?

Any help would be appreciated. Hopefully I’m not missing something glaringly obvious. Cheers :slight_smile:

The name/symbol DNSError is not defined in your code, hence the error. Inside the library, where it was constructed, it is of course defined.

In this case, DNSError comes from Sockets standard library. You can fix your snippet by adding using Sockets and then use Sockets.DNSError instead. (The name DNSError is not exported from Sockets, so it is not enough with using Sockets to bring in the name).


Should HTTP.jl export it? It’s an interesting case, it depends on Sockets.jl, so I’m thinking should it, and packages in general, export types of their dependencies, at least, that they can throw?