Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle RestClient::ServerBrokeConnection

I am using the latest version of rest-client gem and upon external access I see a lots of RestClient::ServerBrokeConnection errors, how should I handle this?

The following call fails

response = RestClient::Request.execute(method: :post, url: url, headers: headers, "Content-Type" => "application/x-www-form-urlencoded")
like image 441
Rpj Avatar asked Dec 08 '14 03:12

Rpj


1 Answers

This error happens when the server broke the connection with the client. You can decide to retry the request or just bubble the error for the user to know about it and handle it.

Because how rest-client handles broken connections as shown here, all you can do is rescue from it

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
like image 168
rafb3 Avatar answered Oct 13 '22 20:10

rafb3