2014-12-08 27 views
5

我正在使用最新版本的rest-client gem,並且在外部訪問時,我看到很多RestClient :: ServerBrokeConnection錯誤,應該如何處理?如何處理RestClient :: ServerBrokeConnection

下調用失敗

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

你見過這個[早些時候SO問題](http://stackoverflow.com/questions/ 11423068 /如何對手柄的例外與 - 紅寶石其餘客戶端)? – 2014-12-10 03:59:23

+0

嗨@Rpj是否能夠使用建議的解決方案? – rafb3 2014-12-16 15:51:11

回答

5

當服務器打破了客戶端的連接發生此錯誤。您可以決定重試該請求,或者只是將錯誤提示給用戶以瞭解並處理該錯誤。

因爲其他客戶端如何處理斷開的連接如圖所示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