开发者

How to handle different FbGraph exceptions at a time in ruby?

I am new to Ruby On Rails & developing a web application with Facebook connectivity implemented in it. I am using omniauth & fb_graph gem to authenticate user & to get user's information.

While posting user's post on our site to his facebook wall, I am facing issues in two different use cases:

  1. If user updates duplicate st开发者_JS百科atus message in my application I am getting following exception

    FbGraph::Unauthorized (OAuthException :: (#506) Duplicate status message):
    
  2. If suppose user changes his facebook password then the user's access token which I get from omniauth becomes invalid & I get following exception

    FbGraph::Unauthorized (OAuthException :: Error validating access token: Session 
    does not match current stored session. 
    This may be because the user changed the password since the time the session 
    was created or Facebook has changed the session for security reasons.):
    

I am currently doing this but I want to perform two different actions for two differnt exceptions. If status message is duplicate, it should handle the first excepion.

In 2nd exception it should ask to reconnect the facebook account to my application so that I can get the new access token.

Please help. Thank you.


According to the documentation, the exception should have code, type, and message attributes. You can tell determine which action to take based on one of those attributes (all exceptions have message, so that is generally useful, but you may find that code or type is better in this particular instance.

begin
  # log in and post comment
rescue FbGraph::Unauthorized => e
  case e.message
  when /Duplicate status message/
    # handle dup code
  when /Error validating access token/
    # handle bad credentials
  else
    raise e
  end
 end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜