mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Raise more semantic error for unsupported schemes
This commit is contained in:
parent
feb66bdc48
commit
c5701e55a5
3 changed files with 9 additions and 6 deletions
|
@ -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
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue