Skip to content

Commit

Permalink
Implement the code portion of passing extras to the expose call.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sutto committed Jun 9, 2012
1 parent 24670fa commit 52db820
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rocket_pants/controller/error_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def lookup_error_context(exception)
# Returns extra error details for a given object, making it useable
# for hooking in external exceptions.
def lookup_error_extras(exception)
{}
context = lookup_error_context exception
context.fetch :extras, {}
end

# Renders an exception as JSON using a nicer version of the error name and
Expand Down
12 changes: 12 additions & 0 deletions spec/rocket_pants/controller/error_handling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@
content['hello'].should == 'There'
end

it 'should default to extracting extras from the context' do
def error.context; {:extras => {:hello => 'There'}} ; end
get :test_error
content['hello'].should == 'There'
end

it 'should let you pass through data via the context in the controller' do
controller_class.send(:define_method, :demo_exception) { error! :throttled, :extras => {:hello => "There"}}
get :demo_exception
content['hello'].should == 'There'
end

it 'should let you register an item in the error mapping' do
controller_class.error_mapping[TestController::ErrorOfDoom] = RocketPants::Throttled
get :test_error
Expand Down

0 comments on commit 52db820

Please sign in to comment.