Skip to content

Commit

Permalink
Merge pull request #260 from dpree/master
Browse files Browse the repository at this point in the history
Add HTTParty::Error base class. Refs #209.
  • Loading branch information
greatuserongithub committed Nov 30, 2013
2 parents be7166c + 5621c87 commit 6cf4fc7
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 6cf4fc7

Please sign in to comment.