Skip to content

Commit

Permalink
Merge pull request #557 from bernd/error-middleware-content-types
Browse files Browse the repository at this point in the history
Pass content_types option to Grape::Middleware::Error
  • Loading branch information
dblock committed Jan 23, 2014
2 parents 4299dfb + faccf6c commit 59ca798
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Next Release
* [#512](https://github.com/intridea/grape/pull/512): Don't create `Grape::Request` multiple times - [@dblock](https://github.com/dblock).
* [#538](https://github.com/intridea/grape/pull/538): Fixed default values for grouped params - [@dm1try](https://github.com/dm1try).
* [#549](https://github.com/intridea/grape/pull/549): Fixed handling of invalid version headers to return 406 if a header cannot be parsed - [@bwalex](https://github.com/bwalex).
* [#557](https://github.com/intridea/grape/pull/557): Pass `content_types` option to `Grape::Middleware::Error` to fix the content-type header for custom formats. - [@bernd](https://github.com/bernd).


0.6.1
Expand Down
1 change: 1 addition & 0 deletions lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ def build_middleware
b.use Rack::Head
b.use Grape::Middleware::Error,
format: settings[:format],
content_types: settings[:content_types],
default_status: settings[:default_error_status] || 500,
rescue_all: settings[:rescue_all],
default_error_formatter: settings[:default_error_formatter],
Expand Down
20 changes: 20 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,26 @@ def subject.enable_root_route!
get '/error.xml'
last_response.headers['Content-Type'].should eql 'application/xml'
end

context 'with a custom content_type' do
before do
subject.content_type :custom, 'application/custom'
subject.formatter :custom, lambda { |object, env| "custom" }

subject.get('/custom') { 'bar' }
subject.get('/error') { error!('error in custom', 500) }
end

it 'sets content type' do
get '/custom.custom'
last_response.headers['Content-Type'].should eql 'application/custom'
end

it 'sets content type for error' do
get '/error.custom'
last_response.headers['Content-Type'].should eql 'application/custom'
end
end
end

context 'custom middleware' do
Expand Down

0 comments on commit 59ca798

Please sign in to comment.