Graceful way to handle execution expired and bad URI errors?

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]

and here’ s the view code:

[code
cache({:controller => “rss”, :action => “feed_widget_details”, :id =>
@page_object.id}, {:expires => 15.minutes}) do

begin
blog_contents = Net::HTTP.get(URI.parse( @blog_url + ‘&=’ +
params[:k] ))
rescue
blog_contents = ‘No blog entries’
blog_contents
end

-%>
<%=blog_contents-%>

<% end -%>
[/code]

I just added the begin rescue block in the view but this seems like it
could be an act of desperation more than a good fix.

Help!

On 13 Jan 2008, at 17:53, Clem R. wrote:

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.

Fred

On 13 Jan 2008, at 18:16, Clem R. wrote:

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

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?

Thanks for your help!

Frederick C. wrote:

On 13 Jan 2008, at 17:53, Clem R. wrote:

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.

Fred

For my case, where do you think the best place for this would be?

Thanks again

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

On 13 Jan 2008, at 18:35, Clem R. wrote:

For my case, where do you think the best place for this would be?

I think i said earlier than I’d have a feed fetcher model to handle
this.

Fred

sorry - my tired eyed didn’t catch.

Thanks again for the help - big help it was.

-E

For my case, where do you think the best place for this would be?

I think i said earlier than I’d have a feed fetcher model to handle
this.

Fred