Skip to content

Commit

Permalink
Merge 081043b into b79bd9c
Browse files Browse the repository at this point in the history
  • Loading branch information
anaumov committed Mar 12, 2019
2 parents b79bd9c + 081043b commit 74a5fd1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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 - [@anaumov](https://github.com/anaumov).

#### Fixes

Expand Down
3 changes: 2 additions & 1 deletion lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ 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)
def error!(message, status = nil, additional_headers = nil)
self.status(status || namespace_inheritable(:default_error_status))
headers = additional_headers.present? ? header.merge(additional_headers) : header
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 74a5fd1

Please sign in to comment.