Hello,
I have a program that takes blog urls that our customers enter
into their profiles. In some cases they enter bad feeds (IE html
pages instead of atom or rss), and it throws these two errors:
execution expired and bad URI errors in the view.
I need to find a graceful way to handle both. Preferably, if I could
find a way to throw an error message for the execution expired after a
certain time period would be great.
Here's the method code:
[code
def feed_widget_details
@page_object = getPageObject
if @page_object.has_chatter_source?(0)
@blog_url =
"#{WEB_SERVER}/controller/rss/blog/#{@page_object.id_unique}"
elsif @page_object.has_chatter_source?(1)
@blog_url = 'http://reverb.feedxi.com/Warm.xml?url=’ +
@page_object.blog_feed
else
@blog_url = @page_object.blog_feed
end
end
[/code]
Hello,
I have a program that takes blog urls that our customers enter
into their profiles. In some cases they enter bad feeds (IE html
pages instead of atom or rss), and it throws these two errors:
execution expired and bad URI errors in the view.
I need to find a graceful way to handle both. Preferably, if I
could
find a way to throw an error message for the execution expired after a
certain time period would be great.
I've done stuff like this
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 2
http.read_timeout = 7
http.start do |http|
http.request_get(some_url)
end
Which will raise Timeout::Error if it takes longer than the indicated
time. You probably also want to rescue things like Net::ProtocolError,
IOError, Errno::ECONNREFUSED as well. Obviously rescue Exception would
take care of all of that, but I don't like casting the net too wide
like that - you could swallow up mistakes that are actually your own
mistakes rather than a bad url or a network problem.
I wouldn't have that in the view at all, I'd have a FeedFetcher model
that did that for me.
Cool - this definitely looks more like what I was trying to do.
You put the code in the model? I thought it would have best ben put
in a helper?
My particular case was a little different but I wouldn't put things
like that in a view. It's not presentation logic or prettification or
anything like that.
Fred