intridea/grape — pull request #450 by robertopedroso (2013-08-04 23:48:35+00:00)
Title: Call rescue_from with a method instead of a block

This PR adds a simple DSL for passing methods to rescue_from, much like Rails permits:

````ruby
rescue_from Sequel::NoMatchingRow, with: rescue_missing_record

def rescue_missing_record
Rack::Response.new('Missing Record', 404)
end
````

This means you can implement and call custom methods in your rescue handlers. At the moment, this is impossible because the passed block is executed via an instance_exec in the context of Grape::Middleware::Error.

The only problem is that this implementation cannot incorporate exception messages into the rescue method. Rails overcomes this limitation by passing the method as a symbol. It then calls the method with something like:

````ruby
handler = method(rescuer)
handler.arity != 0 ? handler.call(exception) : handler.call
````

I'm not quite sure what changes would have to be made to Grape::Middleware::Error to enable this kind of functionality, but I'm hoping this PR is at least a start.