Skip to content

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

@ktimothy

Description

@ktimothy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions