How to handle a read timeout?
Created by: rpr5x
I am working on a project that requires me to make OAuth API calls to an external website. Each API call returns 100 entries of data at a time. My setup looks roughly like the following:
client_id = ''
client_secret = ''
client = OAuth2::Client.new(client_id, client_secret, site: '')
access_token = client.client_credentials.get_token(client_id: client_id, client_secret: client_secret)
response = access_token.get("/data?page=X&size=100")
For the last line, page
is an integer between 1 and a very large number. The issue is that sometimes the last line that executes the GET request returns a Net::ReadTimeout
error because the returned data is very large (it could also be due to my slow internet connection as well). This happens for a few values of page
but not consistently (e.g. if the API call times out for page 1 the first time it was tried, it may not necessarily time out on subsequent tries). Is there a way to specify a larger read timeout to prevent this error from occurring?