Permalink
Browse files

Allow errors to be returned without an exception being thrown

  • Loading branch information...
1 parent 0023acb commit e35452c0b8ed544b215f67e52c4a45a3cb52a419 @kyledrake kyledrake committed Jul 13, 2011
Showing with 14 additions and 3 deletions.
  1. +2 −1 lib/geoloqi/config.rb
  2. +1 −1 lib/geoloqi/session.rb
  3. +1 −1 lib/geoloqi/version.rb
  4. +10 −0 spec/geoloqi_spec.rb
View
@@ -1,10 +1,11 @@
module Geoloqi
class Config
- attr_accessor :client_id, :client_secret, :redirect_uri, :adapter, :enable_logging, :use_hashie_mash
+ attr_accessor :client_id, :client_secret, :redirect_uri, :adapter, :enable_logging, :use_hashie_mash, :throw_exceptions
def initialize(opts={})
opts.each {|k,v| send("#{k}=", v)}
self.enable_logging ||= false
self.use_hashie_mash ||= false
+ self.throw_exceptions ||= true
begin
require 'hashie' if self.use_hashie_mash && !defined?(Hashie::Mash)
rescue LoadError
View
@@ -55,7 +55,7 @@ def run(meth, path, query=nil)
end
hash = JSON.parse response.body
- raise ApiError.new(response.status, hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error']
+ raise ApiError.new(response.status, hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error'] && !config.throw_exceptions
rescue Geoloqi::ApiError
raise Error.new('Unable to procure fresh access token from API on second attempt') if retry_attempt > 0
if hash['error'] == 'expired_token'
View
@@ -1,5 +1,5 @@
module Geoloqi
def self.version
- '0.9.12'
+ '0.9.13'
end
end
View
@@ -76,6 +76,16 @@
end
end
+ describe 'with access token and throw exceptions false' do
+ before do
+ @session = Geoloqi::Session.new :access_token => 'access_token1234', :config => {:throw_exceptions => false}
+ end
+ it 'should not throw api error exception' do
+ response = @session.get 'badmethodcall'
+ expect {response['error'] == 'not_found'}
+ end
+ end
+
describe 'with access token and hashie mash' do
before do
@session = Geoloqi::Session.new :access_token => 'access_token1234', :config => {:use_hashie_mash => true}

0 comments on commit e35452c

Please sign in to comment.