Skip to content

Commit

Permalink
Guarantees specific error_handler catch was called against a more
Browse files Browse the repository at this point in the history
generic exception caller.
  • Loading branch information
manuwell committed Aug 25, 2015
1 parent 033c2e5 commit e9dbb7b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/lotus/controller/configuration.rb
Expand Up @@ -194,7 +194,10 @@ def exception_handler(exception)
handler = nil

@handled_exceptions.each do |exception_class, h|
handler = h if exception.kind_of?(exception_class)
if exception.kind_of?(exception_class)
handler = h
break
end
end

handler || DEFAULT_ERROR_CODE
Expand Down
7 changes: 7 additions & 0 deletions test/action_test.rb
Expand Up @@ -53,6 +53,13 @@
response[2].must_equal ['An inherited exception occurred!']
end

it 'handles exception with specified method' do
response = ErrorCallFromInheritedErrorClassStack.new.call({})

response[0].must_equal 501
response[2].must_equal ['MyCustomError was thrown']
end

it 'handles exception with specified method (symbol)' do
response = ErrorCallWithSymbolMethodNameAsHandlerAction.new.call({})

Expand Down
22 changes: 21 additions & 1 deletion test/fixtures.rb
Expand Up @@ -119,7 +119,27 @@ def call(params)

private
def handler(exception)
status 501, 'Please go away!'
status 501, 'An inherited exception occurred!'
end
end

class ErrorCallFromInheritedErrorClassStack
include Lotus::Action

handle_exception MyCustomError => :handler
handle_exception StandardError => :standard_handler

def call(params)
raise MyCustomError
end

private
def handler(exception)
status 501, 'MyCustomError was thrown'
end

def standard_handler(exception)
status 501, 'An unknown error was thrown'
end
end

Expand Down

0 comments on commit e9dbb7b

Please sign in to comment.