Last active
June 8, 2020 09:41
-
-
Save kirillshevch/a0effd7497bef9f8fa22e4348936f443 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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