Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
basjanssen opened this issue Jul 10, 2018 · 3 comments · May be fixed by #1774
Open

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

basjanssen opened this issue Jul 10, 2018 · 3 comments · May be fixed by #1774
Labels

Comments

@basjanssen
Copy link

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?

@basjanssen
Copy link
Author

When investigating in the grape code, I see that inside_route wil check for a value in the body using .present? This will return false if an empty hash is used. I'm not sure if this should be the case. Returning an empty json object is done returning {}. The body is clearly not empty: it returns a valid json object. However: the grape implementation would regard this as no content -> 204.

@dblock
Copy link
Member

dblock commented Jul 11, 2018

Interesting, I think this is a bug. Try writing a test for it, maybe a fix?

@basjanssen
Copy link
Author

I love to get some feedback. As a grape rookie, I hope I'm on the right track.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants