mirror of
https://github.com/lostisland/faraday.git
synced 2025-08-29 00:03:58 -04:00
Faraday exceptions shouldn't shadow real exceptions
This commit is contained in:
parent
fbf2536168
commit
44dfe35f02
@ -44,7 +44,7 @@ module Faraday
|
||||
|
||||
@app.call env
|
||||
rescue Errno::ECONNREFUSED
|
||||
raise Error::ConnectionFailed, "connection refused"
|
||||
raise Error::ConnectionFailed.new(Errno::ECONNREFUSED)
|
||||
end
|
||||
|
||||
def net_http_class(env)
|
||||
|
@ -26,7 +26,7 @@ module Faraday
|
||||
|
||||
@app.call env
|
||||
rescue Errno::ECONNREFUSED
|
||||
raise Error::ConnectionFailed, "connection refused"
|
||||
raise Error::ConnectionFailed.new(Errno::ECONNREFUSED)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -43,7 +43,7 @@ module Faraday
|
||||
|
||||
@app.call env
|
||||
rescue Errno::ECONNREFUSED
|
||||
raise Error::ConnectionFailed, "connection refused"
|
||||
raise Error::ConnectionFailed.new(Errno::ECONNREFUSED)
|
||||
end
|
||||
|
||||
def in_parallel(options = {})
|
||||
|
@ -1,6 +1,29 @@
|
||||
module Faraday
|
||||
module Error
|
||||
class ClientError < StandardError; end
|
||||
class ClientError < StandardError
|
||||
def initialize(exception)
|
||||
@inner_exception = exception
|
||||
end
|
||||
|
||||
def message
|
||||
@inner_exception.message
|
||||
end
|
||||
|
||||
def backtrace
|
||||
@inner_exception.backtrace
|
||||
end
|
||||
|
||||
alias to_str message
|
||||
|
||||
def to_s
|
||||
@inner_exception.to_s
|
||||
end
|
||||
|
||||
def inspect
|
||||
@inner_exception.inspect
|
||||
end
|
||||
end
|
||||
|
||||
class ConnectionFailed < ClientError; end
|
||||
class ResourceNotFound < ClientError; end
|
||||
class ParsingError < ClientError; end
|
||||
|
@ -23,9 +23,8 @@ module Faraday
|
||||
|
||||
def self.parse(body)
|
||||
ActiveSupport::JSON.decode(body)
|
||||
# TODO: Maybe rescue Exception can be better ...
|
||||
rescue Yajl::ParseError => e
|
||||
raise Faraday::Error::ParsingError
|
||||
rescue Object => err
|
||||
raise Faraday::Error::ParsingError.new(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,8 +19,8 @@ module Faraday
|
||||
|
||||
def self.parse(body)
|
||||
Yajl::Parser.parse(body)
|
||||
rescue Yajl::ParseError => e
|
||||
raise Faraday::Error::ParsingError
|
||||
rescue Object => err
|
||||
raise Faraday::Error::ParsingError.new(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user