如何捕捉考拉:: Facebook :: APIError OAuthException或用户密码重置

Oli*_*ver 7 facebook ruby-on-rails ruby-on-rails-3 koala

我想知道如何捕获考拉oauth异常(例如用户密码重置).

现在这是我到目前为止使用的东西:

rescue_from Koala::Facebook::APIError do
  # redirect to fb auth dialog
end
Run Code Online (Sandbox Code Playgroud)

但这会捕获所有错误..我怎么能只用oauth或只重置密码?

编辑:

找到了一个更明确的问题解决方案:

rescue_from Koala::Facebook::APIError do |exception|
  if exception.fb_error_type == 190
    # password reset - redirect to auth dialog
  else
    raise "Facebook Error: #{exception.fb_error_type}"
  end
end
Run Code Online (Sandbox Code Playgroud)

在此先感谢奥利弗

Nob*_*ita 2

我将向您展示一些我拥有的代码,以及我如何设法捕获和营救 Koala 异常:

def post_message_facebook_wall(message)
    unless self.token.nil?
      begin
        facebook_graph = Koala::Facebook::GraphAPI.new(self.token)
        object_from_koala = facebook_graph.put_wall_post(message)
      rescue Koala::Facebook::APIError => exc
        logger.error("Problems posting to Facebook Wall..."+self.inspect+" "+exc.message)
      end
    end
end
Run Code Online (Sandbox Code Playgroud)

rescue Koala::Facebook::APIError => exc应该可以解决问题。