]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
httputil: nicer UI message when lacking ssl
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 2 Feb 2011 09:04:56 +0000 (10:04 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 2 Feb 2011 09:04:56 +0000 (10:04 +0100)
Rather than complaining about a missing use_ssl= method, if net/https
fails to load we define a mock use_ssl= method that raises a runtime
error making the LoadError message public. This is not the most
user-friendly message (we would prefer not to expose internals), but
it should be clear enough to help owners that forget to read the log
find what's missing.

lib/rbot/core/utils/httputil.rb

index 03671cfea060da9a60d6ebb53694bdc7f5cb20ce..e69120be8e2cbc533481087b2f9a2936c263fae3 100644 (file)
@@ -14,8 +14,18 @@ require 'iconv'
 begin
   require 'net/https'
 rescue LoadError => e
-  error "Couldn't load 'net/https':  #{e.pretty_inspect}"
+  error "Couldn't load 'net/https':  #{e}"
   error "Secured HTTP connections will fail"
+  # give a nicer error than "undefined method `use_ssl='"
+  ::Net::HTTP.class_eval <<-EOC
+    define_method :use_ssl= do |val|
+      # does anybody really set it to false?
+      break if !val
+      raise _("I can't do secure HTTP, sorry (%{msg})") % {
+        :msg => e.message
+      }
+    end
+  EOC
 end
 
 # To handle Gzipped pages