Skip to content

Commit

Permalink
Merge adee5c0 into b79bd9c
Browse files Browse the repository at this point in the history
  • Loading branch information
anaumov committed Mar 11, 2019
2 parents b79bd9c + adee5c0 commit 9207e92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Your contribution here.
* [#1864](https://github.com/ruby-grape/grape/pull/1864): Adds `finally` on the API - [@myxoh](https://github.com/myxoh).
* [#1869](https://github.com/ruby-grape/grape/pull/1869): Fix issue with empty headers after `error!` method call. It happened when headers were set in `before` block or endpoint body.

#### Fixes

Expand Down
1 change: 1 addition & 0 deletions lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def version
# @param message [String] The message to display.
# @param status [Integer] the HTTP Status Code. Defaults to default_error_status, 500 if not set.
def error!(message, status = nil, headers = nil)
headers = headers.present? ? header.merge(headers) : header
self.status(status || namespace_inheritable(:default_error_status))
throw :error, message: message, status: self.status, headers: headers
end
Expand Down
11 changes: 11 additions & 0 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,17 @@ def app
expect(last_response.headers['X-Custom']).to eq('value')
end

it 'returns headers set before error!' do
subject.get '/hey' do
header 'X-Test', 'sample'
error!({ 'dude' => 'rad' }, 403)
end

get '/hey.json'
expect(last_response.status).to eq(403)
expect(last_response.headers['X-Test']).to eq('sample')
end

it 'sets the status code for the endpoint' do
memoized_endpoint = nil

Expand Down

0 comments on commit 9207e92

Please sign in to comment.