Skip to content

Commit

Permalink
Add HTTParty::Error base class. Refs #209.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsingr committed Nov 28, 2013
1 parent be7166c commit 5621c87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/httparty/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module HTTParty
# @abstact Exceptions raised by HTTParty inherit from Error
class Error < StandardError; end

# Exception raised when you attempt to set a non-existant format
class UnsupportedFormat < StandardError; end
class UnsupportedFormat < Error; end

# Exception raised when using a URI scheme other than HTTP or HTTPS
class UnsupportedURIScheme < StandardError; end
class UnsupportedURIScheme < Error; end

# @abstract Exceptions which inherit from ResponseError contain the Net::HTTP
# response object accessible via the {#response} method.
class ResponseError < StandardError
class ResponseError < Error
# Returns the response of the last request
# @return [Net::HTTPResponse] A subclass of Net::HTTPResponse, e.g.
# Net::HTTPOK
Expand Down
23 changes: 23 additions & 0 deletions spec/httparty/exception_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))

describe HTTParty::Error do
subject { described_class }

its(:ancestors) { should include(StandardError) }

describe HTTParty::UnsupportedFormat do
its(:ancestors) { should include(HTTParty::Error) }
end

describe HTTParty::UnsupportedURIScheme do
its(:ancestors) { should include(HTTParty::Error) }
end

describe HTTParty::ResponseError do
its(:ancestors) { should include(HTTParty::Error) }
end

describe HTTParty::RedirectionTooDeep do
its(:ancestors) { should include(HTTParty::ResponseError) }
end
end

0 comments on commit 5621c87

Please sign in to comment.