浏览代码

Better error handling when feeds don't parse

master
Adrian Short 12 年前
父节点
当前提交
e2eb60a6a7
共有 2 个文件被更改,包括 11 次插入2 次删除
  1. +5
    -1
      app/controllers/feeds_controller.rb
  2. +6
    -1
      app/models/feed.rb

+ 5
- 1
app/controllers/feeds_controller.rb 查看文件

@@ -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 查看文件

@@ -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,


正在加载...
取消
保存