Skip to content

Commit fcd8bad

Browse files
committed
Inject foul higher up the exception stack
1 parent 8694de0 commit fcd8bad

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/httparty/exceptions.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module HTTParty
4-
FOUL_ERRORS = [
4+
COMMON_NETWORK_ERRORS = [
55
EOFError,
66
Errno::ECONNABORTED,
77
Errno::ECONNREFUSED,
@@ -24,15 +24,19 @@ module HTTParty
2424
# @abstract Exceptions raised by HTTParty inherit from Error
2525
class Error < StandardError; end
2626

27+
# @abstract Exception raised by HTTParty inherit from this because it is funny
28+
# and if you don't like fun you should be using a different library.
29+
class Foul < Error; end
30+
2731
# Exception raised when you attempt to set a non-existent format
28-
class UnsupportedFormat < Error; end
32+
class UnsupportedFormat < Foul; end
2933

3034
# Exception raised when using a URI scheme other than HTTP or HTTPS
31-
class UnsupportedURIScheme < Error; end
35+
class UnsupportedURIScheme < Foul; end
3236

3337
# @abstract Exceptions which inherit from ResponseError contain the Net::HTTP
3438
# response object accessible via the {#response} method.
35-
class ResponseError < Error
39+
class ResponseError < Foul
3640
# Returns the response of the last request
3741
# @return [Net::HTTPResponse] A subclass of Net::HTTPResponse, e.g.
3842
# Net::HTTPOK
@@ -53,6 +57,6 @@ class RedirectionTooDeep < ResponseError; end
5357
# Exception that is raised when request redirects and location header is present more than once
5458
class DuplicateLocationHeader < ResponseError; end
5559

56-
# Exception that wraps common net/http errors when the :foul option is enabled
57-
class Foul < Error; end
60+
# Exception that is raised when common network errors occur.
61+
class NetworkError < Foul; end
5862
end

lib/httparty/request.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ def perform(&block)
172172
result = handle_unauthorized
173173
result ||= handle_response(chunked_body, &block)
174174
result
175-
rescue *FOUL_ERRORS => e
176-
raise options[:foul] ? HTTParty::Foul.new("#{e.class}: #{e.message}") : e
175+
rescue *COMMON_NETWORK_ERRORS => e
176+
raise options[:foul] ? HTTParty::NetworkError.new("#{e.class}: #{e.message}") : e
177177
end
178178
end
179179

0 commit comments

Comments
 (0)