Open
Description
On version 0.16.2, I have the following configured;
class Foos < Grape::API
include AuthCheck
...
resource :foo do
...
get '/:foo/:id' do
...
end
# But no POST route
end
end
module AuthCheck
extend ActiveSupport::Concern
included do
before do
error!('Unauthorized', 401) unless headers_has_secret
end
end
end
A GET request to foo/<foo-id>
will either respond with a 200 or a 400 as expected. A POST however will 500;
ArgumentError (uncaught throw :error):
app/api/my_auth_check.rb:8:in `block (2 levels) in <module:AuthCheck>'
Because it's a throw, this is the only line of the stack trace. If I force a throw and send a GET request I do get a big stack trace, which means the throw is caught in that case. If I write a post
block, I get the expected behavior.
It seems like grape is running the before block before it checks to see whether the request has a matching route. Is this the intended behaviour?