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

  • SEARCH
  • Home
  • 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 8290475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:49:34+00:00 2026-06-08T12:49:34+00:00

I have a method that checks for broken links: def self.check_prod_links require ‘net/http’ results

  • 0

I have a method that checks for broken links:

def self.check_prod_links
  require 'net/http'
  results = []
  Product.find_each(:conditions =>{:published => 1}) do |product|
    url = product.url 
    id = product.id
    uri = URI(url)
    begin
      response = Net::HTTP.get_response(uri)
    rescue
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      request = Net::HTTP::Get.new(uri.request_uri)
      response = http.request(request)
    rescue
      response = Net::HTTP.get_response("http://" + uri)  
    rescue => e
      p "Problem getting url: #{url} Error Message: #{e.message}"
    end
    p "Checking URL = #{url}. ID = #{id}. Response Code = #{response.code}" 
    unless response.code.to_i == 200
      product.update_attribute(:published, 0) 
      results << product
    end
  end
  return results
end

My understanding was that rescue => e should log all exceptions not caught by the previous rescue statements, and the method should continue running, however for some reason when certain URL’s are checked, the script quits with the following exception:

SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A:
unknown protocol

How can I set this up so that if an exception is caught, it will be printed, and the task will continue running?

Also, how can I call the results array to render in the mailer view, is there a better way to do this so that I can add all products that were unpublished to an already existing mailer?

Thanks!

  • 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-08T12:49:36+00:00Added an answer on June 8, 2026 at 12:49 pm

    I’m pretty sure your first rescue will be the only one that works. Specifying => e just tells Ruby to store the exception in a variable called e. I’m thinking the code in your first rescue block is raising the error you are seeing and there is nothing else rescuing it. To be honest, this is kind of a mess of code and you might be better off refactoring it into smaller methods.

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

Sidebar

Related Questions

I have a method that checks spots in a 2D array, and it also
i currently have a method that checks what is around the centre item in
I have method that returns module path of given class name def findModulePath(path, className):
I have a method that checks certain things and returns a Boolean based on
So I have a method that checks for internet connection, but only during the
I have a method that checks some assumptions and either follows the happy path,
I have a method that checks all of the combinations of 5 different conditions
So I have a method that checks if the device is connected to the
I have tried to fix a method that checks if the user has Skype
I have a method that checks a JSON payload for JSON decoding errors, and

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.