【发布时间】:2021-01-25 05:22:55
【问题描述】:
我一般都遇到过这个问题,但从来没有真正解决过,但是今天早上我有一个具体的案例。
我的应用程序与 Despatch Bay Shipping API 集成: https://github.com/despatchbay/despatchbay-api-v15/wiki
我不会用所有的代码来打扰你,但是今天早上他们的端点失败了,我在这行代码中遇到了一个错误,它根据我发送的包裹数据从他们的 API 请求运输服务:
Dim Services As dbShipping.ServiceType() = DespatchBay.Services.Get(Company, Box.ToParcel(ParcelValue:=ParcelTotal), DBRecipient)
他们的代码在他们自己的网站上也失败了。
我暂时“克服”了这个问题,方法是将上面需要 Services 对象的代码包装在 Try/Catch 中,但实际失败需要相当长的时间。
那我该怎么做,而不是写:
Try
Dim Services As dbShipping.ServiceType() = DespatchBay.Services.Get(Company, Box.ToParcel(ParcelValue:=ParcelTotal), DBRecipient)
Catch
' Do stuff it broke
End Try
这样写
Wait for Despatch Bay:
Dim Services As dbShipping.ServiceType() = DespatchBay.Services.Get(Company, Box.ToParcel(ParcelValue:=ParcelTotal), DBRecipient)
But if it takes too long
'Do stuff, it broke
End waiting for Despatch Bay
我只想让那个 API 请求的响应超时,不是我的整个代码块。
如果重要,我正在寻找.NetStandard 解决方案,而不是特定于框架的解决方案。
【问题讨论】:
标签: asp.net-core client .net-standard apiclient