Skip to content

Commit

Permalink
[#1719] Fix missing headers before error! call
Browse files Browse the repository at this point in the history
  • Loading branch information
anaumov committed Mar 11, 2019
1 parent b79bd9c commit e3dfcba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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 e3dfcba

Please sign in to comment.