Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantees specific error_handler catch was called against a more #120

Merged
merged 1 commit into from Aug 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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