In my rails app, I am using ActiveResource to access another service, and I’d like to gracefully handle the exception that occurs when that resource is offline (server is down/ip is blocked etc.). With no response being returned, my app generates this error:
Errno::ECONNREFUSED in UsersController
I’d like to do a ‘rescue_from’ in my application controller so that it’ll handle the error whenever it occurs, but not sure what the params would be, or it this kind of exception is even trappable at this point.
Should/can I test for the availability of a resource?
I can do this, but it catches every error, and I’d like to catch the specific connection type error I am getting.
rescue_from Exception, do
...
end
It might be easier to assume everything’s okay, and then deal with the exception when it arises. You can use rescue_from in your application controller (or probably your users controller, if it’s a local error):
Note: I started this before you updated your post, but the good news is that
Errno::ECONNREFUSEDis a class – not a constant – so you can use it instead of the genericException:Hope that helps!