Browse files

Raise friendly error when template host cannot be resolved.

By default, Rummager will attempt to connect to for
its templates.  If you're not using the standard hosts (*
to serve the apps then visiting your instance of Rummager will result
in the fairly opaque:

    SocketError at /
    getaddrinfo: nodename nor servname provided, or not known

This change to slimmer will catch the SocketError exception and raise a
more friendly Slimmer::CouldNotRetrieveTemplate error, which is what it
currently does when it can't connect to port 80.  This makes it much
easier to diagnose these problems in client apps, e.g. Rummager.
  • Loading branch information...
chrisroos committed Jul 9, 2012
1 parent 392b20e commit 890849d6f25d9273e1862648b9079d9619546395
Showing with 12 additions and 0 deletions.
  1. +2 −0 lib/slimmer/skin.rb
  2. +10 −0 test/skin_test.rb
@@ -78,6 +78,8 @@ def load_template template_name
raise TemplateNotFoundException, "Unable to fetch: '#{template_name}' from '#{url}' because #{e}", caller
rescue Errno::ECONNREFUSED => e
raise CouldNotRetrieveTemplate, "Unable to fetch: '#{template_name}' from '#{url}' because #{e}", caller
+ rescue SocketError => e
+ raise CouldNotRetrieveTemplate, "Unable to fetch: '#{template_name}' from '#{url}' because #{e}", caller
def template_url template_name
@@ -40,4 +40,14 @@ def test_should_raise_appropriate_exception_when_cant_reach_template_host
skin.load_template 'example'
+ def test_should_raise_appropriate_exception_when_hostname_cannot_be_resolved
+ skin = asset_host: "http://non-existent.domain/"
+ expected_url = "http://non-existent.domain/templates/example.html.erb"
+ stub_request(:get, expected_url).to_raise(SocketError)
+ assert_raises(Slimmer::CouldNotRetrieveTemplate) do
+ skin.load_template 'example'
+ end
+ end

0 comments on commit 890849d

Please sign in to comment.