Skip to content

Commit

Permalink
Raise friendly error when template host cannot be resolved.
Browse files Browse the repository at this point in the history
By default, Rummager will attempt to connect to static.dev.gov.uk for
its templates.  If you're not using the standard hosts (*.dev.gov.uk)
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 890849d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/slimmer/skin.rb
Expand Up @@ -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
end

def template_url template_name
Expand Down
10 changes: 10 additions & 0 deletions test/skin_test.rb
Expand Up @@ -40,4 +40,14 @@ def test_should_raise_appropriate_exception_when_cant_reach_template_host
skin.load_template 'example'
end
end

def test_should_raise_appropriate_exception_when_hostname_cannot_be_resolved
skin = Slimmer::Skin.new 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
end

0 comments on commit 890849d

Please sign in to comment.