What's the stack? Why do you think it's a problem with the Grape API?
There's a lot going on in this API, a database, some session code, etc. Strip it down or write it as a spec in this project.
@dblock Here is the stack:
Puma caught this error: undefined method
bad_request?' for #<Rack::ShowExceptions:0x000000035d6620> (NoMethodError) (erb):145:inpretty'
/usr/lib/ruby/2.3.0/erb.rb:864:ineval' /usr/lib/ruby/2.3.0/erb.rb:864:inresult'
/var/lib/gems/2.3.0/gems/rack-2.0.3/lib/rack/show_exceptions.rb:96:inpretty' /var/lib/gems/2.3.0/gems/rack-2.0.3/lib/rack/show_exceptions.rb:32:inrescue in call'
/var/lib/gems/2.3.0/gems/rack-2.0.3/lib/rack/show_exceptions.rb:23:incall' /var/lib/gems/2.3.0/gems/rack-2.0.3/lib/rack/common_logger.rb:33:incall'
/var/lib/gems/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:231:incall' /var/lib/gems/2.3.0/gems/rack-2.0.3/lib/rack/chunked.rb:54:incall'
/var/lib/gems/2.3.0/gems/rack-2.0.3/lib/rack/content_length.rb:15:incall' /var/lib/gems/2.3.0/gems/puma-3.9.1/lib/puma/configuration.rb:224:incall'
/var/lib/gems/2.3.0/gems/puma-3.9.1/lib/puma/server.rb:602:inhandle_request' /var/lib/gems/2.3.0/gems/puma-3.9.1/lib/puma/server.rb:435:inprocess_client'
/var/lib/gems/2.3.0/gems/puma-3.9.1/lib/puma/server.rb:299:inblock in run' /var/lib/gems/2.3.0/gems/puma-3.9.1/lib/puma/thread_pool.rb:120:inblock in spawn_thread'
It only happens on the requests handled by the Grape part (API).
Actually, what directly cause this exception is that Moneta does not define a "session" method for Grape. So there should have be an exception of "undefined method session'", which also appears in the terminal. But after the exception of "session", another exception(undefined methodbad_request?') is thrown and will be displayed in the response.
Maybe there is something wrong happened when Grape tried to generate a response for the exception in it?
I think you understand what's going on, turn it into a basic minimal project or spec (eg. https://github.com/ruby-grape/grape-on-rack).
@mopperwhite, have you fixed this error?
@incubus Not yet. I could only read error messages using terminals.
This is actually a Sinatra issue. It extends Rack::ShowExceptions and sets the TEMPLATE constant in order to override the displayed exception.
https://github.com/sinatra/sinatra/blob/master/lib/sinatra/show_exceptions.rb#L365
The problem is that the template calls the bad_request? method that only exists in Sinatra::ShowExceptions, so any other Rack app like Grape will raise an error when showing exceptions.
@jkowens thanks!
Sinatra 2.0.1.rc1 has been released and if all goes well 2.0.1 will be released this weekend. A fix for the described problem is included. I think it's safe to close this issue.
cc: @dblock
Does anyone have or wants to contribute an integration spec for this?
Most helpful comment
This is actually a Sinatra issue. It extends
Rack::ShowExceptionsand sets theTEMPLATEconstant in order to override the displayed exception.https://github.com/sinatra/sinatra/blob/master/lib/sinatra/show_exceptions.rb#L365
The problem is that the template calls the
bad_request?method that only exists inSinatra::ShowExceptions, so any other Rack app like Grape will raise an error when showing exceptions.