Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the retry parameter results in method calls no longer raise errors #174

Open
Sokre95 opened this issue Nov 8, 2022 · 0 comments
Open

Comments

@Sokre95
Copy link

Sokre95 commented Nov 8, 2022

Example:

Without using retry config:

api_client.crm.contacts.basic_api.get_by_id(contact_id: 123)
  # => raises an `Hubspot::Crm::Contacts::ApiError` error with status code 404

Using retry config:

retry_config = {
    429 => { max_retries: 3, seconds_delay: 5 },
    500..530 => { max_retries: 2, seconds_delay: 10 }
  }

response = api_client.crm.contacts.basic_api.get_by_id(contact_id: 123, retry: retry_config)
  # => does not raise error but returns instance instead
response.is_a?(Hubspot::Crm::Contacts::ApiError)
=> true
response.code
=> 404

I don't think it is good that gem behaves like this. Just because you start using retries suddenly it no longer raises exceptions and that is not expected at all.

Example, method like this doesn't work anymore if you add retry block

  def get_contact_by_id(id:)
    api_client.crm.contacts.basic_api.get_by_id(contact_id: id)
  rescue Hubspot::Crm::Contacts::ApiError => e
    return nil if e.code == 404

    raise e
  end

I don't actually mind if gem returns error response or actually raises an error. I just expect that the interface will behave the same regardless of whether retry option is used or not.

Related to

def call_api_with_retry(api_method, params_to_pass, retry_config, &block)
call_api_with_rescue(api_method, params_to_pass) do |error|
opts = retry_config.detect{ |k,v| k === error.code }&.last
retries = opts&.dig(:max_retries) || 5
block.call(error) unless block.nil?
response = error
while retries > 0 && opts
sleep opts[:seconds_delay] if opts[:seconds_delay]
response = call_api_with_rescue(api_method, params_to_pass) do |e|
block.call(e) unless block.nil?
e
end
return response unless response.respond_to?(:code)
opts = retry_config.detect{ |k,v| k === response.code }&.last
retries -= 1
end
response
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant