elixirelixir-poison

HTTPoison: request getting closed


https://yts.lt/api/v2/list_movies.json?query_term=tt11296058

Above URL is always available and gives the expected output (JOSN) while accessing from browser

But sometimes (randomly) while access same URL using httposion, following error received:

request: HTTPoison.get(url, [], follow_redirect: true)

error {:error, %HTTPoison.Error{id: nil, reason: :closed}}

what could be the reason here.


Solution

  • Usually, this happens due to the network glitches when the TCP request failed to route to the remote and backward. That means, TCP request failed to complete, and there is no actual response from the remote.

    The browser would likely retry the request silently. You can safely do the same, but remember to throttle so that your code won’t enter the infinite loop.