Sha256: 14f131437068575331874c2852babe7487ea000712ee74b2d9a131318749cb0e

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module LedgerSync
  class Error
    class AdaptorError < Error
      attr_reader :adaptor
      attr_reader :response

      def initialize(adaptor:, message:, response: nil)
        @adaptor = adaptor
        @response = response
        super(message: message)
      end

      class AuthenticationError < self; end
      class AuthorizationError < self; end
      class ConfigurationError < self; end

      class MissingAdaptorError < self
        def initialize(message:)
          super(
            message: message,
            adaptor: nil,
          )
        end
      end

      class AdaptorValidationError < self
        attr_reader :attribute, :validation

        def initialize(message:, adaptor:, attribute:, validation:)
          @attribute = attribute
          @validation = validation
          super(
            message: message,
            adaptor: adaptor,
          )
        end
      end

      class ThrottleError < self
        attr_reader :rate_limiting_wait_in_seconds

        def initialize(adaptor:, message: nil, response: nil)
          message ||= 'Your request has been throttled.'
          @rate_limiting_wait_in_seconds = LedgerSync.adaptors.config_from_class(
            adaptor_class: adaptor.class
          ).rate_limiting_wait_in_seconds

          super(
            adaptor: adaptor,
            message: message,
            response: response
          )
        end
      end

      class UnknownURLFormat < self
        attr_reader :resource

        def initialize(*args, resource:, **keywords)
          super(
            *args,
            {
              message: "Unknown URL format for #{resource.class}"
            }.merge(keywords)
          )
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ledger_sync-1.3.5 lib/ledger_sync/error/adaptor_errors.rb