Permalink
Browse files

Fix: return immediately on fail!

  • Loading branch information...
1 parent 0873551 commit a9d2d6731d6dd8390183375a85edc767538594a3 Jesse Stuart committed Oct 3, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/omniauth/strategies/tent.rb
View
11 lib/omniauth/strategies/tent.rb
@@ -10,6 +10,7 @@ class Tent
Error = Class.new(StandardError)
AppCreateFailure = Class.new(Error)
+ StateMissmatchError = Class.new(Error)
option :get_app, lambda { |entity| }
option :app, { :name => nil, :icon => nil, :description => nil, :scopes => {}, :redirect_uris => nil }
@@ -34,6 +35,10 @@ def request_phase
f.text_field 'Entity', 'entity'
end.to_response
end
+ rescue AppCreateFailure => e
+ fail!(:app_create_failure, e)
+ rescue StateMissmatchError => e
+ fail!(:state_missmatch)
end
def callback_phase
@@ -90,7 +95,7 @@ def create_app
if (app = res.body) && !app.kind_of?(::String)
set_app(app)
else
- fail!(:app_create_failure, AppCreateFailure.new(res.body))
+ raise AppCreateFailure.new(res.body)
end
end
@@ -117,15 +122,15 @@ def build_uri_params!(uri, params)
end
def verify_state!
- fail!(:state_missmatch) unless get_state(:state) == request.params['state']
+ raise StateMissmatchError unless get_state(:state) == request.params['state']
end
def create_app_authorization!
client = ::TentClient.new(get_state(:server_url), :mac_key_id => get_app[:mac_key_id],
:mac_key => get_app[:mac_key],
:mac_algorithm => get_app[:mac_algorithm])
res = client.app.authorization.create(get_app[:id], :code => request.params['code'])
- fail!(:app_creation_failure) if res.body.kind_of?(::String)
+ raise AppCreateFailure.new(res.body) if res.body.kind_of?(String)
@app_authorization = Hashie::Mash.new(res.body)
end

0 comments on commit a9d2d67

Please sign in to comment.