Clem Rock
2008-Jan-13 17:53 UTC
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 = ''<title type="text">No blog entries</title>'' 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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-13 18:06 UTC
Re: Graceful way to handle execution expired and bad URI errors?
On 13 Jan 2008, at 17:53, Clem Rock wrote:> > 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. Fred> 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 = ''<title type="text">No blog entries</title>'' > 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! > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Clem Rock
2008-Jan-13 18:16 UTC
Re: Graceful way to handle execution expired and bad URI err
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 Cheung wrote:> On 13 Jan 2008, at 17:53, Clem Rock 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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-13 18:26 UTC
Re: Graceful way to handle execution expired and bad URI err
On 13 Jan 2008, at 18:16, Clem Rock 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> Thanks for your help! > > > Frederick Cheung wrote: >> On 13 Jan 2008, at 17:53, Clem Rock 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 > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Clem Rock
2008-Jan-13 18:35 UTC
Re: Graceful way to handle execution expired and bad URI err
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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-13 19:05 UTC
Re: Graceful way to handle execution expired and bad URI err
On 13 Jan 2008, at 18:35, Clem Rock 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> 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 > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Clem Rock
2008-Jan-14 00:31 UTC
Re: Graceful way to handle execution expired and bad URI err
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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---