gpt4 book ai didi

ruby-on-rails - 如何处理 RestClient::ServerBrokeConnection

转载 作者:行者123 更新时间:2023-12-03 16:04:52 25 4
gpt4 key购买 nike

我正在使用最新版本的 rest-client gem 并且在外部访问时我看到很多 RestClient::ServerBrokeConnection 错误,我应该如何处理?

以下调用失败

response = RestClient::Request.execute(method: :post, url: url, headers: headers, "Content-Type" => "application/x-www-form-urlencoded")

最佳答案

当服务器断开与客户端的连接时会发生此错误。您可以决定重试请求或只是冒泡错误让用户了解并处理它。

因为rest-client 如何处理断开的连接,如图here ,你所能做的就是从中拯救

begin
response = RestClient::Request.execute(method: :post, url: url, headers: headers, "Content-Type" => "application/x-www-form-urlencoded")
rescue RestClient::ServerBrokeConnection
// retry or do something
end

关于ruby-on-rails - 如何处理 RestClient::ServerBrokeConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27350747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com