【问题标题】:Handle oauth errors with Google Ruby Client?使用 Google Ruby 客户端处理 oauth 错误?
【发布时间】:2013-10-29 19:10:22
【问题描述】:

我在 Rails Web 应用程序中使用 Google API Ruby 客户端(gem 'google-api-client'),我想知道如何捕获 oauth 流程中的特定错误。特别是,我应该在救援声明中寻找什么?下面是用户授权后重定向调用的函数:

require 'google/api_client'

def google_auth_finish
  begin 
    client = Google::APIClient.new
    client.authorization.client_id = GOOGLE_CLIENT_ID
    client.authorization.client_secret = GOOGLE_CLIENT_SECRET
    ...
  rescue ## WHAT GOES HERE TO IDENTIFY THE ERROR?
    # Handle the error
    logger.info "There was an error." 
  end 
end

在某处是否有已定义错误的参考?我已经搜索并找不到它。

【问题讨论】:

    标签: ruby-on-rails ruby error-handling google-api


    【解决方案1】:

    我知道这是几年前提出的问题,但我确实只是遇到了这个问题并且遇到了这个问题。你只是漏掉了一小部分。这对我有用。我还是比较新的,但就我而言,它阻止了程序崩溃并打印出错误消息,然后程序继续运行。

    rescue Exception => error
          puts "Error #{error}"
    end
    

    【讨论】:

      【解决方案2】:

      试试theseRaising An Exception

      【讨论】:

      • 我的问题是关于 Google::APIClient 引发的错误以及如何指定它们。
      猜你喜欢
      • 2023-03-12
      • 2016-03-15
      • 2015-10-31
      • 2016-06-07
      • 2014-06-18
      • 2013-01-15
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多