-
Notifications
You must be signed in to change notification settings - Fork 32
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
Grape logger always log 500 http response code for rescued exceptions #10
Comments
Yeah, that's not ideal behavior. But unfortunately I don't see how to hook into the error handlers registered with |
@ridiculous we can get all the rescue handlers: rescue_handlers = @env['api.endpoint'].namespace_reverse_stackable(:rescue_handlers) And find an executable {ActiveRecord::RecordInvalid=>#<Proc:0x00000005ce4960@/project/app/api.rb:14>} We can invoke the proc and get its results. Usually there is an I'm still thinking about the implementation... And I think we need to work in that way to recatch those exceptions. |
I didn't bother to update the tests yet. Let me know what you think and we go from there |
@ridiculous yes, I have also analyzed |
Hi @ridiculous. Any news about that issue? :) |
Nothing new. What do you think of my solution in #15, overloading |
If you're fine with #15, I'm happy to release a new version with it |
same issue here - how about a simpler version with no overloading but a configurable status code per exception class? e.g. validation errors would get a 400/422 and everything else a 500. EDIT context:
and we could have something like: custom_status_codes = [
{ exception_class: Grape::Exceptions::ValidationErrors, code: 422 }
] |
@dakull but Grape already can have custom exception statuses and it will be some kind of overhead (to set the status code multiple times). I think that overloading of |
I'm running in this issue as well. Why not,
??? |
Did you try it? Does it work? |
Yes, I tried it and it works :). However, since I just started using grape recently, I don't have enough experience to say whether there are issues with this approach. So, it would be good for someone with more grape experience / understanding to try it as well. |
Hi. While exploring the
grape-middleware-logger
logs I discovered that all requests with errors that are preprocessed withrescue_from
are marked with 500 response code:Log:
I looked at the source code of the gem and added some trace to the code. And what am I found is that
rescue_from
are invoked aftergrape-middleware-logger
methods such asafter_exception
andafter_failure
. So the real status code (and maybe some extra info) does not fall into the log, only 500. I think that is a wrong behaviour.Gemfile.lock
What do you think about that, @ridiculous?
The text was updated successfully, but these errors were encountered: