1

I need Faraday to retry my POST request every time when it gets 202 http status as a response. I am aware of this module, yet I don't really get how to make use of it, since 202 doesn't throw an error or something and retry_if: block is not called for 202 response.

I had some success with this middleware but it resends request only once, while 202 response may occur 2 and more times in a row.

I wonder if someone could show me a way to do it using retry module or Faraday middleware.

Yaroslav V.
  • 121
  • 2
  • 8

1 Answers1

0

in theory 202 is a success https://httpstatuses.com/202, it's an acceptance of an asynchronous request, so you really should only have to send your post once, and if you get a 202, you're done your job. That link states "There is no facility in HTTP for re-sending a status code from an asynchronous operation." So, I think you'd really need to be checking for completion another way. However, you could do something like this (just spitballing here):

   conn = Faraday.new(url: url, :ssl => {:verify => verify_ssl_cert}) do |faraday|
        faraday.adapter Faraday.default_adapter
   end
   response = conn.get
   while response.status == 202
      # repeat code above
   end

But you run various risks like infinitely looping