I have 3 servers running beside my app and I am sending RESTful request to them, but I want to have a loop that tries one of these three until it gets accurate response. In my execution when it gets Bad Respond from first server program raises "BadRespondError" and I cannot rescue it in my codes because execution goes to rescue.rb in "actionpack" gem. How could I solve that problem? Can I solve it without working on Execeptions and Errors just with a simple loop or if it is not possible, how could I rescue BadRespondError in my code other than rescue.rb
Here are my code Requesting ....
@response = carrot.dcs_request(uri, {
"dcs.source" => "etools",
"query" => @query,
"dcs.output.format" => "JSON",
"dcs.clusters.only" => "false"
})
@json = @response
@response = JSON.parse(@response)
....
Request function
def dcs_request(uri, data)
boundary = Array::new(16) { "%2.2d" % rand(99) }.join()
extheader = {
"content-type" => "multipart/form-data; boundary=___#{ boundary }___"
}
client = HTTPClient.new
response = client.post_content(uri, data, extheader)
end
So think like uri as an array and I want to loop on it until I get accurate response from one of them.