Sha256: cf363eb6a6ed9a4af805ebacb3f353f27faaa764fb7adc2300af3099937e50ef

Contents?: true

Size: 1.73 KB

Versions: 19

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module MyApiClient
  module ErrorHandling
    # Processes the `retry` option.
    class RetryOptionProcessor < ServiceAbstract
      # @param error_handling_options [Hash]
      #   Options for the retry.
      # @option raise [MyApiClient::Error]
      #   Raises specified error when an invalid response detected.
      #   Should be inherited `MyApiClient::Error` class.
      # @option retry [TrueClass, Hash]
      #   If the error detected, retries the API request. Requires `raise` option.
      #   You can set `true` or `retry_on` options (`wait` and `attempts`).
      # @option block [Proc, nil]
      #   Executes the block when error detected.
      #   The `block` option is forbidden to be used with the` retry` option.
      # @return [Hash]
      #   Options for `retry_on`.
      # @return [nil]
      #   If `retry` is not specified.
      def initialize(error_handling_options:)
        @error_handling_options = error_handling_options
      end

      private

      attr_reader :error_handling_options

      def call
        retry_options = error_handling_options.delete(:retry)
        return unless retry_options

        verify_error_handling_options
        retry_options = {} unless retry_options.is_a? Hash
        retry_options
      end

      # Requires `retry` option and forbid `block` option.
      def verify_error_handling_options
        if !error_handling_options[:raise]
          raise 'The `retry` option requires `raise` option. ' \
                'Please set any `raise` option, which inherits `MyApiClient::Error` class.'
        elsif error_handling_options[:block]
          raise 'The `block` option is forbidden to be used with the` retry` option.'
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
my_api_client-1.2.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-1.1.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-1.0.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.27.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.26.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.25.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.24.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.23.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.22.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.21.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.20.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.19.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.18.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.17.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.16.1 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.16.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.15.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.14.0 lib/my_api_client/error_handling/retry_option_processor.rb
my_api_client-0.14.0.pre lib/my_api_client/error_handling/retry_option_processor.rb