gpt4 book ai didi

timeout - 使用 ActiveMerchant 时如何处理超时?

转载 作者:行者123 更新时间:2023-12-02 10:05:29 25 4
gpt4 key购买 nike

有时,在本地开发时,我的连接会下降,虽然这希望不会在生产中发生,但它会引发一个问题,即当 ActiveMerchant 发送到支付网关(在我的情况下发送到 SagePay)时,我可能应该处理来自 ActiveMerchant 的超时。

我在文档中看不到执行此操作的方法,我想知道是否有最佳实践方法来处理此问题?

最佳答案

我相信这个问题与 AM 的 ruby​​ 实现有关(如果我错了,请纠正我)。

发生超时 ( link to source ) 时,

ActiveMerchant 引发 ActiveMerchant::ConnectionError。因此我们可以简单地处理异常。例如:

begin
# Your ActiveMerchant staff here
rescue ActiveMerchant::ConnectionError => e
# timeout handler
end

有时,在 SagePay 的情况下,使用 open_timeoutread_timeout 类属性 ( link to source ) 控制超时也很有用:

ActiveMerchant::SagePay.open_timeout = 5 # timeout for opening the connection is set to 5 seconds
ActiveMerchant::SagePay.read_timeout = 10 # timeout for reading from opened connection is set to 10

关于timeout - 使用 ActiveMerchant 时如何处理超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19960214/

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