0

I'm using the following function in Ruby on Rails:

  def isGoogleEmailAddress?(email_domain)
    Resolv::DNS.open({:nameserver=>["8.8.8.8"]}) do |r|
      mx = r.getresources(email_domain,Resolv::DNS::Resource::IN::MX)
      if mx.any? {|server| server.exchange.to_s.downcase.include? "google"} then
        return true
      end
      return false
    end
  end

Is there a way to handle the issue where Resolv fails, timeouts, errors etc?

halfer
  • 19,824
  • 17
  • 99
  • 186
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012

1 Answers1

-2

Look through the documentation for the Resolv class and add exception handlers for the various errors/exceptions the class can raise.

They're easy to pick out. Look for classes ending in error and timeout.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303