Skip to content

Instantly share code, notes, and snippets.

@kirillshevch
Last active June 8, 2020 09:41
Show Gist options
  • Save kirillshevch/a0effd7497bef9f8fa22e4348936f443 to your computer and use it in GitHub Desktop.
Save kirillshevch/a0effd7497bef9f8fa22e4348936f443 to your computer and use it in GitHub Desktop.
class SomeClass
attr_reader :id, :retries
ApiError = Class.new(StandardError)
RETRY_LIMIT = 3
def initialize(id)
@id = id
@retries = 0
end
def call
execute
end
private
def execute
api_client.get(id)
rescue StandardError => e
@retries = @retries + 1
retries > RETRY_LIMIT ? raise(e) : execute
end
def api_client
raise ApiError, 'client_error'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment