Skip to content
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

Specific exception handlers are not called when using rescue_from with option 'with:' #1364

Closed
ktimothy opened this issue Apr 18, 2016 · 0 comments

Comments

@ktimothy
Copy link
Contributor

I ran into the strange behaviour while refactoring my api and moving error handling into separate file. So I wrote this minimal example to reproduce the issue.

Here I use blocks to handle specific exceptions and call specific helper method:

class API < Grape::API
  helpers do 
    def argument_error e
      rack_response({ error: "argument_error_block" }.to_json)
    end

    def all_errors e
      rack_response({ error: "all_errors_block" }.to_json)
    end
  end

  rescue_from ArgumentError do |e| argument_error(e); end
  rescue_from :all do |e| all_errors(e); end

  get :argument_error do
    raise ArgumentError
  end
end

When I request /argument_error API responds, as intended, with {"error":"argument_error_block"}. But if I use with: in rescue_from

  rescue_from ArgumentError, with: :argument_error
  rescue_from :all, with: :all_errors

I start to receive {"error":"all_errors_block"} and never get to argument_error helper.

ktimothy added a commit to ktimothy/grape that referenced this issue Apr 18, 2016
ktimothy added a commit to ktimothy/grape that referenced this issue Apr 20, 2016
…ape#1364.

Now exception handler in options can be a symbol (or string) name of
helper method to handle exception.
ktimothy added a commit to ktimothy/grape that referenced this issue Apr 20, 2016
…ape#1364.

Now exception handler in options can be a symbol (or string) name of
helper method to handle exception.
ktimothy added a commit to ktimothy/grape that referenced this issue Apr 22, 2016
…ape#1364.

Now exception handler in options can be a symbol (or string) name of
helper method to handle exception.
@dblock dblock closed this as completed in 044dad7 Apr 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant