Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在ruby中一次处理不同的FbGraph异常?_Ruby On Rails_Ruby_Exception Handling_Facebook Graph Api - Fatal编程技术网

Ruby on rails 如何在ruby中一次处理不同的FbGraph异常?

Ruby on rails 如何在ruby中一次处理不同的FbGraph异常?,ruby-on-rails,ruby,exception-handling,facebook-graph-api,Ruby On Rails,Ruby,Exception Handling,Facebook Graph Api,我是RubyonRails的新手&开发一个实现了Facebook连接的web应用程序。我正在使用&gem对用户进行身份验证并获取用户信息 在将用户在我们网站上的帖子发布到他的facebook墙上时,我在两个不同的用例中面临着问题: 如果用户在我的应用程序中更新了重复的状态消息,我将得到以下异常 FbGraph::Unauthorized (OAuthException :: (#506) Duplicate status message): FbGraph::Unauthorized (OAu

我是RubyonRails的新手&开发一个实现了Facebook连接的web应用程序。我正在使用&gem对用户进行身份验证并获取用户信息

在将用户在我们网站上的帖子发布到他的facebook墙上时,我在两个不同的用例中面临着问题:

  • 如果用户在我的应用程序中更新了重复的状态消息,我将得到以下异常

    FbGraph::Unauthorized (OAuthException :: (#506) Duplicate status message):
    
    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.):
    
  • 如果假设用户更改了他的facebook密码,那么我从omniauth获得的用户访问令牌将无效&我得到以下异常

    FbGraph::Unauthorized (OAuthException :: (#506) Duplicate status message):
    
    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.):
    
  • 我目前正在执行,但我想针对两个不同的异常执行两个不同的操作。如果状态消息重复,则应处理第一个例外

    在第二个例外中,它应该要求将facebook帐户重新连接到我的应用程序,以便我可以获得新的访问令牌

    请帮忙。 谢谢。

    根据,异常应具有
    代码
    类型
    消息
    属性。您可以根据这些属性中的一个确定要采取的操作(所有异常都有
    消息
    ,因此这通常很有用,但您可能会发现
    代码
    类型
    在这个特定实例中更好

    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