Monday 18 August 2014

Httparty Timeout Error when Calling a local Controller from an API

When we try to call a local controller from an API it forms a loop as the Web application trying to send the request and the one trying to receive the request are same.


This can be solved by setting a timeout in the Httparty post or get call

    response = HTTParty.post(url, :timeout => 0, :body => {}.to_json, :head => {})

The default  timeout will be "60" seconds and by setting it to "0" will solve the Timeout problem but we even have to handle the Timeout exeption so, we can do as given below

 begin
    response = HTTParty.post(url, :timeout => 0, :body => {}.to_json, :head => {})
 rescue Timeout::Error
       p "Could not post to #{url}: timeout"     
 end  
 

No comments:

Post a Comment