Depending on how you use the library, there are different ways to rescue the exception.
In the library
Assuming you created a wrapper to access some kind of web service, you can have the wrapper rescue the exception and always return a "safe" data.
In the action
If you call a specific method in the action and the method success is a requirement for the action, then you can rescue it in the action.
In the following example I rescue the error and show a specific template to handle the problem.
def action
perform_external_call
rescue Timeout::Error => e
@error = e
render :action => "error"
end
In the controller
If the method call can occur in many different actions, you might want to use rescue_from
.
class TheController < ApplicationController
rescue_from Timeout::Error, :with => :rescue_from_timeout
protected
def rescue_from_timeout(exception)
# code to handle the issue
end
end