ruby-grape / ruby-grape/grape

Returning an empty hash in a HTTP delete results in an exception

Open
#1,768 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug?
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

After upgrading to Grape >= 0.19.1, the default status code for DELETE is now 204 instead of 200.
When returning a response which is not empty (for example {'key'=>'value'}, a 200 is returned with the correct response body.

When a non empty hash is returned on webrick (default development rails server) this goes well: the hash is returned. However, if an empty hash is provided {}, it results in an exception:

[2018-07-10 15:38:03] ERROR TypeError: no implicit conversion of Hash into String
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/handler/webrick.rb:113:in `block in service'
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/body_proxy.rb:31:in `each'
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/body_proxy.rb:31:in `each'
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/body_proxy.rb:31:in `each'
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/body_proxy.rb:31:in `each'
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/body_proxy.rb:31:in `each'
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/body_proxy.rb:31:in `each'
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/body_proxy.rb:31:in `each'
	/Users/bas.janssen/.rvm/gems/ruby-2.4.4@rails4/gems/rack-1.6.10/lib/rack/handler/webrick.rb:112:in `service'
	/Users/bas.janssen/.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/webrick/httpserver.rb:140:in `service'
	/Users/bas.janssen/.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/webrick/httpserver.rb:96:in `run'
	/Users/bas.janssen/.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/webrick/server.rb:308:in `block in start_thread'

with the following output (http 500):

<HTML>
    <HEAD>
        <TITLE>Internal Server Error</TITLE>
    </HEAD>
    <BODY>
        <H1>Internal Server Error</H1>
    no implicit conversion of Hash into String
        <HR>
        <ADDRESS>
     WEBrick/1.3.1 (Ruby/2.4.4/2018-03-28) at
     localhost:3005
    </ADDRESS>
    </BODY>
</HTML>

Adding an explicit status of 200 solves this:

delete do
  status 200
  {}
end

Is this issue known, can someone confirm this and can it be solved in some way?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the DELETE endpoint that returns {} with the default 204 status on WEBrick, then inspect the stack locations named in rack/handler/webrick.rb and rack/body_proxy.rb. Confirm the behavior against the non-empty hash and explicit-200 cases; done means the empty response no longer raises the reported Hash-to-String exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.