Sha256: 0d87155b9cfa8fadab43c4c783aec5da52f52125b037d3e70b5428443a4f185d

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

module LedgerSync
  class Error
    class LedgerError < Error
      attr_reader :client
      attr_reader :response

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

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

      class MissingLedgerError < self
        def initialize(message:)
          super(
            message: message,
            client: nil,
          )
        end
      end

      class LedgerValidationError < self
        attr_reader :attribute, :validation

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

      class ThrottleError < self
        attr_reader :rate_limiting_wait_in_seconds

        def initialize(client:, message: nil, response: nil)
          message ||= 'Your request has been throttled.'
          @rate_limiting_wait_in_seconds = LedgerSync.ledgers.config_from_class(
            client_class: client.class
          ).rate_limiting_wait_in_seconds

          super(
            client: client,
            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

4 entries across 4 versions & 1 rubygems

Version Path
ledger_sync-1.4.4 lib/ledger_sync/error/ledger_errors.rb
ledger_sync-1.4.2 lib/ledger_sync/error/ledger_errors.rb
ledger_sync-1.4.1 lib/ledger_sync/error/ledger_errors.rb
ledger_sync-1.4.0 lib/ledger_sync/error/ledger_errors.rb