7

I have a method in rails to send post requests to a third party API. The code looks similar to the following:

data = HTTParty.post("url",
  :headers=> {'Content-Type' => 'application/json'},
  :body=> { update => true, first_name => "name" }
)

With this, after exactly one minute, the process is terminated with the following error.

<Net::HTTPGatewayTimeOut 504 GATEWAY_TIMEOUT readbody=true>
sawa
  • 165,429
  • 45
  • 277
  • 381
Gopi Raju
  • 219
  • 3
  • 13

2 Answers2

17

Set the default by:

module HTTParty
  default_timeout your_preferred_timeout
end

or set it individually by:

data = HTTParty.post("url",
  headers: {"Content-Type" => "application/json"},
  body: {update => true, first_name => "name"},
  timeout: your_preferred_timeout
)
sawa
  • 165,429
  • 45
  • 277
  • 381
-1

you can try

 data = HTTParty.post("url",
  headers: {"Content-Type" => "application/json"},
  body: {update => true, first_name => "name"},
  open_timeout: 0.5,
  write_timeout:1,
  read_timeout:3
)

also you can reference
https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#attribute-i-write_timeout