Skip to content

Commit

Permalink
fix(ruby-grape#1922): Update CHANGELOG and running rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
jcagarcia committed Nov 21, 2023
1 parent a77be51 commit 7486d3c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#### Features

* [#2371](https://github.com/ruby-grape/grape/pull/2371): Use a param value as the `default` value of other param - [@jcagarcia](https://github.com/jcagarcia).
* [#2377](https://github.com/ruby-grape/grape/pull/2377): Allow to use instance variables values inside rescue_from - [@jcagarcia](https://github.com/jcagarcia).
* Your contribution here.

#### Fixes
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def error!(message, status = nil, additional_headers = nil)
# Returns:
# A Rack::Response object containing the specified message, status, and headers.
#
def rack_response(message, status, headers = { Rack::CONTENT_TYPE => content_type })
def rack_response(message, status = 200, headers = { Rack::CONTENT_TYPE => content_type })
message = ERB::Util.html_escape(message) if headers[Rack::CONTENT_TYPE] == 'text/html'
Rack::Response.new([message], Rack::Utils.status_code(status), headers)
end
Expand Down
6 changes: 2 additions & 4 deletions lib/grape/middleware/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ def run_rescue_handler(endpoint, handler, error)
handler.arity.zero? ? endpoint.instance_exec(&handler) : endpoint.instance_exec(error, &handler)
end)

if error?(response)
response = error!(response[:message], response[:status], response[:headers])
end
response = error!(response[:message], response[:status], response[:headers]) if error?(response)

if response.is_a?(Rack::Response)
response
Expand All @@ -142,7 +140,7 @@ def run_rescue_handler(endpoint, handler, error)
end

def error?(response)
response && response.is_a?(Hash) && response[:message] && response[:status] && response[:headers]
response.is_a?(Hash) && response[:message] && response[:status] && response[:headers]
end
end
end
Expand Down

0 comments on commit 7486d3c

Please sign in to comment.