-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
before
block called before valid route is checked for.
#1402
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
Comments
I think this is by design, but I can see how it's unclear in https://github.com/ruby-grape/grape#before-and-after. I'd appreciate at least some specs that definitely answer this question if we don't have any, and a README update. Does |
I'm seeing something kind of similar to this, but it's not the same problem. In my case, I was seeing a 500 error when using a wrong request method (for example, calling the before do
require_special_header!
end And error!(:special_header_missing, 400) unless request.headers['X-Special-Header'].present? This ends up raising module Grape
class Router
...
def method_not_allowed(env, methods, endpoint)
env[Grape::Env::GRAPE_METHOD_NOT_ALLOWED] = true
current = endpoint.dup
current.instance_eval do
@lazy_initialized = false
lazy_initialize!
run_filters befores, :before
@block = proc do
raise Grape::Exceptions::MethodNotAllowed, header.merge('Allow' => methods)
end
end
current.call(env)
end This shouldn't happen with What do you think? Should the |
(In my particular case I'll likely move that kind of headers check to a |
@rosa maybe you're onto something, want to try writing a spec for this and seeing whether bringing in I still would love better documentation on when these are called, it's not obvious that |
I was going to add some spec and found out that there is already a spec that shows how |
I think I just struggled with this for the last few days while trying to figure out why a test had broken when everything else was working fine in an upgrade from 0.15.0 to 0.17.0 (0.16.x had a bug with I explain the problem somewhat more in-depth here before I found this issue. Essentially we have an endpoint I tried to bisect to see when this behavior was introduced, but due to the |
So based on the README with the order of |
@connorshea If something wasn't explained in UPGRADING PR that? |
I started on the UPGRADING.md PR, but after thinking on it and testing for a bit it seems that this wasn't the source of the problem I was having (though I don't fully understand why This is the section I was going to add, but I'm pretty sure it's inaccurate: Routes are no longer validated prior to a
|
You should focus on master only. Explain what "valid" and "invalid" means by providing working examples and try to PR it. We can discuss it there. Opened #1521 for release, add your +1. |
Thank you @dblock! |
On version 0.16.2, I have the following configured;
A GET request to
foo/<foo-id>
will either respond with a 200 or a 400 as expected. A POST however will 500;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?
The text was updated successfully, but these errors were encountered: