-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fixed finding handler in error middleware. Fixes #1364 #1365
Conversation
Need CHANGELOG and a test, please. |
Sure, will do that tomorrow. |
Looks like the issue is a little bit deeper. Last call to rescue_from using with: overwrites previously set with: value. For now option 'with:' is stored now in rescue_options in middleware/error, which makes it common for all exceptions. I think the option 'with:' should be stored for each exception type separately. |
686c96f
to
30761e6
Compare
@@ -157,9 +157,9 @@ def represent(model_class, options) | |||
|
|||
def extract_with(options) | |||
return unless options.key?(:with) | |||
with_option = options[:with] | |||
with_option = options.delete(:with) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to dup
options first, since you're modifying the original hash or continue just doing options[:with]
.
See minor-ish comments, otherwise good to merge? |
Yes, just made small fixes. |
0cb447c
to
aece0c9
Compare
@@ -104,7 +104,7 @@ def rescue_from(*args, &block) | |||
handler = block | |||
end | |||
|
|||
options = args.extract_options! | |||
options = args.extract_options!.dup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what I meant. This particular one actually returns a new hash every time according to the documentation, so a dup
is just doing extra unnecessary work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what's wrong with just checking options[:with]
below? Why does it need to delete
that value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular one actually returns a new hash every time
Oh, shame to me =)
Ok, we should have discussed it a little bit before I made my changes =). The option :with
was used in middleware/error. I removed that usage, and stored its value in rescue_handlers
hash.
So I decided to delete :with
from options
hash just to clean it from unused key. And that's why I had to fix request_response_spec.rb.
Sorry to be a pest, I have more questions ;) |
No problem ;) |
@ktimothy I am so sorry to be thick and slow here (typing this from an island in the Caribbean). Amend the code to what you want it to be, and re-explain the whole thing to me like a two year old. Really appreciate your patience. |
…ape#1364. Now exception handler in options can be a symbol (or string) name of helper method to handle exception.
aece0c9
to
ad89c7b
Compare
@dblock I hope you have a good time there =) Ok, here is the whole thing. At first I handled different exceptions using block syntax: rescue_from ArgumentError do |e|
rack_response({error: 'argument_error'}.to_json)
end
rescue_from :all do |e|
rack_response({error: 'internal_error'}.to_json)
end Then I wanted to move exception handlers from api class to helpers module. So I tried to use options rescue_from ArgumentError, with: :rescue_argument_error
rescue_from :all, with: :all_errors_handler which made my api code much better. But, unfortunately, grape stopped handling As a solution I suggest to store Error middleware now does not check rescue_options[:with], it tries to take handler from |
Merged via 044dad7, thanks for the clear explanation! |
Awesome, thanks! |
No description provided.