Faraday exceptions shouldn't shadow real exceptions

This commit is contained in:
rick 2010-10-05 10:27:47 -07:00
parent fbf2536168
commit 44dfe35f02
6 changed files with 31 additions and 9 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 = {})

View File

@ -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

View File

@ -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

View File

@ -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