Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:51:46+00:00 2026-06-06T12:51:46+00:00

In my rails app, I am using ActiveResource to access another service, and I’d

  • 0

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   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:51:48+00:00Added an answer on June 6, 2026 at 12:51 pm

    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):

    class ApplicationController < ActionController::Base
        rescue_from(Errno::ECONNREFUSED) do |e|
            flash[:warning] = 'Hey!  Bad things happened!'
            render :template => 'my/error/page'
        end
    end
    

    Note: I started this before you updated your post, but the good news is that Errno::ECONNREFUSED is a class – not a constant – so you can use it instead of the generic Exception:

    irb(main):009:0> Errno::ECONNREFUSED
    => Errno::ECONNREFUSED
    irb(main):010:0> Errno::ECONNREFUSED.class
    => Class
    irb(main):011:0> Errno::ECONNREFUSED.superclass
    => SystemCallError
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails app whose major part is to query another web-service using
I'm using ActiveResource in my rails app to talk to another rails app (both
I tried using ActiveResource to parse a web service that was more like a
I am developing a web app (using rails) that I will be launching within
I'm using Authlogic with my Ruby on Rails App. I would like user to
In my Rails app, I am used to using syntax like the following in
I'm trying to layout a Rails app using Devise for authentication. I'd like to
I am implementing a like system in my rails app using David Celis gem
I have a REST API that I am trying to access using Rails 3.0.1
I have two Rails apps, one client using ActiveResource and one service. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.