Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is their a way to create Dummy Response with 500 code in HTTParty

Tags:

ruby

httparty

Here my HTTParty code

      response = HTTParty.post(api_url,body: form_data,timeout: 5)
      rescue Timeout::Error
      ## create dummy response with 500 error code
      response = HTTParty::Response.new()
      ensure
       response

all I'm trying to do is ensure If the HTTParty is unable to connect the given website create a dummy response body objec

But when I try to create a dummy Response object like this

     ## response = HTTParty::Response.new(Rack::Request.new(api_url),Rack::Response.new('TimeOut Error',500),'TimeOutError')

but this does not work because my response object does not respond_to to_hash

Can anyone suggest a better way to accomplish the same

like image 335
Ratatouille Avatar asked Sep 16 '25 22:09

Ratatouille


1 Answers

In case anybody comes looking after 4 years, one could try the following:

httparty_req = HTTParty::Request.new Net::HTTP::Get, '/'
nethttp_resp = Net::HTTPInternalServerError.new('1.1', 500, 'Internal Server Error')
response = HTTParty::Response.new(httparty_req, nethttp_resp, lambda {''}, body: '')
like image 169
thunder Avatar answered Sep 19 '25 18:09

thunder