Upgrading Faraday gem: RuntimeError: Adapter should be set using the `adapter` method, not `use`

Upgrading Faraday gem: RuntimeError: Adapter should be set using the `adapter` method, not `use`

我对 RoR 比较陌生,现在我想将法拉第从 0.15.4 升级到 0.16.2,我想我需要改变将法拉第插入中间件堆栈的方式。但是我该怎么做呢?

升级 faraday 后 gem 我从 Minitest 得到以下错误:

RuntimeError: Adapter should be set using the `adapter` method, not `use`

通常谷歌搜索确切的错误信息对我来说很好,不幸的是这次我没那么幸运,只在法拉第代码中找到了文字字符串:)

法拉第在我的一个测试文件中如下使用时引发此错误:

def extend_middleware(builder)
  builder.use Ahora::Middleware::RequestLogger, SemanticLogger[Reader]
  builder.use Faraday::Adapter::Typhoeus
end

我的印象是解决方案应该相对简单,只更改上面的 builder.use 行。但是我不知道如何将其转换为错误消息中提到的 adapter 方法。如果有人能指出 'use' 和 'adapter' 方法之间的区别(我想了解这个问题!)并可能指出解决方案,那将对我有很大帮助:D

Faraday 团队 put online 有一份文档可以帮助解决 0.15.4 版的任何向后兼容性错误。

有一个部分与您的问题有关:

In order to specify the adapter you now MUST use the #adapter method on the connection builder. If you don't do so and your adapter inherits from Faraday::Adapter then Faraday will raise an exception. Otherwise, Faraday will automatically push the default adapter at the end of the stack causing your request to be executed twice.

class OfficialAdapter < Faraday::Adapter
  ...
end

class MyAdapter
  ...
end

# This will raise an exception
conn = Faraday.new(...) do |f|
  f.use OfficialAdapter
end

# This will cause Faraday inserting the default adapter at the end of the stack
conn = Faraday.new(...) do |f|
  f.use MyAdapter
end

# You MUST use `adapter` method
conn = Faraday.new(...) do |f|
  f.adapter AnyAdapter
end