Skip to content

Commit c1f2d8b

Browse files
committed
Bug: rendering actually well-formed JSON.
1 parent 5de736e commit c1f2d8b

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/grape/middleware/error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def formatter_for(api_format)
3636
end
3737

3838
def format_json(message)
39-
{ :error => message }
39+
{ :error => message }.to_json
4040
end
4141

4242
def format_txt(message)

spec/grape/api_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def two
507507
raise "rain!"
508508
end
509509
get '/exception'
510-
last_response.body.should eql '{:error=>"rain!"}'
510+
last_response.body.should eql '{"error":"rain!"}'
511511
end
512512
it 'should rescue all errors' do
513513
subject.error_format :txt
@@ -523,7 +523,7 @@ def two
523523
error!("Access Denied", 401)
524524
end
525525
get '/error'
526-
last_response.body.should eql '{:error=>"Access Denied"}'
526+
last_response.body.should eql '{"error":"Access Denied"}'
527527
end
528528
end
529529

spec/grape/middleware/exception_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def app
6565
run ExceptionApp
6666
end
6767
get '/'
68-
last_response.body.should == '{:error=>"rain!"}'
68+
last_response.body.should == '{"error":"rain!"}'
6969
end
7070

7171
it 'should be possible to specify a custom formatter' do

0 commit comments

Comments
 (0)