Skip to content

Commit

Permalink
Fix #296: ArgumentError with default error formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Dec 25, 2012
1 parent f03a1ff commit 8adf0f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.2.4 (Next Release)
====================

* [#296](https://github.com/intridea/grape/issues/296): Fix: ArgumentError with default error formatter - [@dblock](https://github.com/dblock).
* Your contribution here.

0.2.3 (24/12/2012)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/error_formatter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def formatter_for(api_format, options = {})
spec = formatters(options)[api_format]
case spec
when nil
lambda { |message, backtrace, options| message }
Grape::ErrorFormatter::Txt
when Symbol
method(spec)
else
Expand Down
13 changes: 12 additions & 1 deletion spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ class CommunicationError < RuntimeError; end
end
end

describe ".format for error" do
describe ".error_format" do
it 'should rescue all errors and return :txt' do
subject.rescue_from :all
subject.format :txt
Expand All @@ -896,6 +896,17 @@ class CommunicationError < RuntimeError; end
last_response.body.start_with?("rain!\r\n").should be_true
end

it 'should rescue all errors with a default formatter' do
subject.default_format :foo
subject.content_type :foo, "text/foo"
subject.rescue_from :all
subject.get '/exception' do
raise "rain!"
end
get '/exception.foo'
last_response.body.should start_with "rain!"
end

context "class" do
before :each do
class CustomErrorFormatter
Expand Down

0 comments on commit 8adf0f9

Please sign in to comment.