I have many classes inheriting the Page class. They share the same update_ended method which tries to update the status when the page ends.
Since these Page classes faces different problems, a mix of different net/http agents are used, including OpenURI, Net::HTTP and Mechanize.
def update_ended
fetch_page(...)
rescue OpenURI::HTTPError, Net::HTTPNotFound, Mechanize::ResponseCodeError
self.ended = true
...
self.save!
end
I want to catch 404 page not found exception and end a Page object. Currently my implementation is not fine-grained enough to do that. Different exceptions have different ways of telling what kind of HTTP status it is.
In my case above, what’s the best way to determine the code (e.g. 404) from various implementation of HTTP errors? Do I use multiple rescue or do I have lots of if statements in the rescue?
Probably easiest is to catch everything and look at the message: