How to handle RestClient::ServerBrokeConnection
Asked Answered
V

1

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")
Vlaminck answered 8/12, 2014 at 3:1 Comment(2)
Have you seen this earlier SO question?Operant
hey @Vlaminck were you able to use the proposed solution?Renitarenitent
R
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
Renitarenitent answered 11/12, 2014 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.