Fix improper handling of invalid resource.
Merge pull request #9 from johnou/fix_connection_handling

Fix improper handling of invalid resource.