Bläddra i källkod

Better error handling when feeds don't parse

master
Adrian Short 12 år sedan
förälder
incheckning
e2eb60a6a7
2 ändrade filer med 11 tillägg och 2 borttagningar
  1. +5
    -1
      app/controllers/feeds_controller.rb
  2. +6
    -1
      app/models/feed.rb

+ 5
- 1
app/controllers/feeds_controller.rb Visa fil

@@ -41,7 +41,11 @@ class FeedsController < ApplicationController
# POST /feeds
# POST /feeds.json
def create
@feed = Feed.new(params[:feed])
begin
@feed = Feed.new(params[:feed])
rescue
redirect_to '/', error: "Feed didn't parse. Please check it with the validator."
end

respond_to do |format|
if @feed.save


+ 6
- 1
app/models/feed.rb Visa fil

@@ -15,7 +15,7 @@ class Feed
validates :title, :presence => true
validates_format_of :feed_url, :with => URI::regexp(%w(http https)), :message => "must be a valid URL"
after_create :get
before_create :get
# Fetch and parse feed contents from web

@@ -31,6 +31,11 @@ class Feed
Feedzirra::Feed.add_common_feed_element('generator', :as => :generator)

feed = Feedzirra::Feed.fetch_and_parse(@feed_url)
# We fetched the feed OK but couldn't parse it. HTTP 200 OK
if feed.is_a? Fixnum
raise
end

self.set(
:title => feed.title,


Laddar…
Avbryt
Spara