I have built a web app at myapp.heroku.com where “myapp” is actually the random name generated by heroku. When I hit it with my web browser it works. When I hit it with Ruby Rest-Client (gem rest-client v1.6.3) as follows:
irb(main):024:0> response=RestClient.get "http://myapp.heroku.com"
It craps out with the following:
RestClient::InternalServerError: 500 Internal Server Error
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client- 1.6.3/lib/restclient/abstract_response.rb:48:in `return!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:228:in `process_result'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:176:in `block in transmit'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:627:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:170:in `transmit'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:64:in `execute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:33:in `execute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient.rb:68:in `get'
from (irb):24
from C:/Ruby192/bin/irb:12:in `<main>'
When I use the same client with better known URLs, such as “http://www.google.com”, or “http://www.heroku.com”, it works fine, the content of the URL downloads, and everything is good. When I use the same client with a version of the application running at “http://localhost:3000”, it works fine too.
Am I missing something in my rest-client client which prevents it from GETting data from an app hosted at heroku.com?
============ EDIT ==== additional info ===========
After sleeping on it, I tried:
irb> require 'net/http'
irb> NET::HTTP.get_print URI.parse "http://myapp.heroku.com"
It worked fine.
I goofed.
Upon checking “heroku logs”, I found an exception in my code which caused the 500 error. The exception was because of a type casting difference between the PG database in heroku, and my local SQLite3 database. Once I fixed it, everything went well. I suspect that the 500 error also caused my site to be temporarily unaccessible, which is why the subdomain on which my site is hosted did not return anything.
Moral of the story? rest-client works. Heroku works. Rest-client (IMO) shouldn’t throw exceptions for a 500, but just return the HTTP response code and let the app deal with it. However, if I whine more, I’ll also have to fork & fix…