5

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")
Rpj
  • 5,348
  • 16
  • 62
  • 122

1 Answers1

8

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
rafb3
  • 1,694
  • 12
  • 12