From c5701e55a51a003a98b7fab234845395aab7b674 Mon Sep 17 00:00:00 2001 From: Sandro Turriate Date: Thu, 19 Nov 2009 23:39:11 -0500 Subject: [PATCH] Raise more semantic error for unsupported schemes --- lib/httparty/exceptions.rb | 7 +++++-- lib/httparty/request.rb | 2 +- spec/httparty_spec.rb | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/httparty/exceptions.rb b/lib/httparty/exceptions.rb index 423f989..88d0822 100644 --- a/lib/httparty/exceptions.rb +++ b/lib/httparty/exceptions.rb @@ -1,7 +1,10 @@ module HTTParty # Exception raised when you attempt to set a non-existant format class UnsupportedFormat < StandardError; end - + + # Exception raised when using a URI scheme other than HTTP or HTTPS + class UnsupportedURIScheme < StandardError; end + # Exception that is raised when request has redirected too many times class RedirectionTooDeep < StandardError; end -end \ No newline at end of file +end diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index b869625..78bec68 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -30,7 +30,7 @@ module HTTParty end unless SupportedURISchemes.include? new_uri.class - raise ArgumentError, "Cannot parse '#{new_uri}' as a supported URI class" + raise UnsupportedURIScheme, "'#{new_uri}' Must be HTTP or HTTPS" end new_uri diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index d9ce5be..d206e00 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -352,20 +352,20 @@ describe HTTParty do stub_http_response_with('google.html') lambda do HTTParty.get('http://google.com') - end.should_not raise_error(ArgumentError) + end.should_not raise_error(HTTParty::UnsupportedURIScheme) end it "should accept https URIs" do stub_http_response_with('google.html') lambda do HTTParty.get('https://google.com') - end.should_not raise_error(ArgumentError) + end.should_not raise_error(HTTParty::UnsupportedURIScheme) end it "should raise an ArgumentError on URIs that are not http or https" do lambda do HTTParty.get("file:///there_is_no_party_on/my/filesystem") - end.should raise_error(ArgumentError) + end.should raise_error(HTTParty::UnsupportedURIScheme) end it "should raise an InvalidURIError on URIs that can't be parsed at all" do