Permalink
Browse files

remove Faraday::Error module, add Faraday::Error base class

  • Loading branch information...
1 parent 14b458a commit a6c6f1612c225335bf3bf94cf0b88e2e9a315671 @technoweenie committed Oct 20, 2012
Showing with 35 additions and 30 deletions.
  1. +34 −29 lib/faraday/error.rb
  2. +1 −1 test/middleware_stack_test.rb
View
@@ -1,40 +1,45 @@
module Faraday
- module Error
- class ClientError < StandardError
- attr_reader :response
+ class Error < StandardError; end
+ class MissingDependency < Error; end
- def initialize(ex, response = nil)
- @wrapped_exception = nil
- @response = response
+ class ClientError < Error
+ attr_reader :response
- if ex.respond_to?(:backtrace)
- super(ex.message)
- @wrapped_exception = ex
- elsif ex.respond_to?(:each_key)
- super("the server responded with status #{ex[:status]}")
- @response = ex
- else
- super(ex.to_s)
- end
- end
+ def initialize(ex, response = nil)
+ @wrapped_exception = nil
+ @response = response
- def backtrace
- if @wrapped_exception
- @wrapped_exception.backtrace
- else
- super
- end
+ if ex.respond_to?(:backtrace)
+ super(ex.message)
+ @wrapped_exception = ex
+ elsif ex.respond_to?(:each_key)
+ super("the server responded with status #{ex[:status]}")
+ @response = ex
+ else
+ super(ex.to_s)
end
+ end
- def inspect
- %(#<#{self.class}>)
+ def backtrace
+ if @wrapped_exception
+ @wrapped_exception.backtrace
+ else
+ super
end
end
- class ConnectionFailed < ClientError; end
- class ResourceNotFound < ClientError; end
- class ParsingError < ClientError; end
- class TimeoutError < ClientError; end
- class MissingDependency < StandardError; end
+ def inspect
+ %(#<#{self.class}>)
+ end
+ end
+
+ class ConnectionFailed < ClientError; end
+ class ResourceNotFound < ClientError; end
+ class ParsingError < ClientError; end
+ class TimeoutError < ClientError; end
+
+ [:MissingDependency, :ClientError, :ConnectionFailed, :ResourceNotFound,
+ :ParsingError, :TimeoutError].each do |const|
+ Error.const_set(const, Faraday.const_get(const))
end
end
@@ -99,7 +99,7 @@ def test_handler_comparison
end
def test_unregistered_symbol
- err = assert_raise(RuntimeError) { build_stack :apple }
+ err = assert_raise(Faraday::Error) { build_stack :apple }
assert_equal ":apple is not registered on Faraday::Middleware", err.message
end

0 comments on commit a6c6f16

Please sign in to comment.