我有一个需要为每个帖子发送的pingback列表。它看起来像这样:
def send_trackback
#do stuff
begin
Pingback::Client.new.ping(source_uri, target_uri)
trackback.status = 1
trackback.save
rescue
trackback.status = 2
trackback.save
nil
end
end
以下是完整错误:
XMLRPC::FaultException (The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.):
app/controllers/posts_controller.rb:67:in `block in send_trackback'
app/controllers/posts_controller.rb:62:in `send_trackback'
app/controllers/posts_controller.rb:8:in `pingback'
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (4.6ms)
状态从0开始,但是如果ping回来失败那没关系,但是我想要状态设置2并且我希望它继续不向rails发送错误。如果成功,我希望状态设置为1。
不应该开始 - 救援块处理这个?我错过了什么?
答案 0 :(得分:0)
那应该有用。看起来异常是在pingback / send_trackback中触发而不是send_pingback