Sha256: b4ec2cec97ba91b1ec1fa7dccd32ccfa670ccffb22f6eda4c21aef1fafe0f3b6

Contents?: true

Size: 911 Bytes

Versions: 3

Compression:

Stored size: 911 Bytes

Contents

# frozen_string_literal: true

class Valvat
  class Lookup
    class Fault < Response
      def self.cleanup(hash)
        fault = hash[:fault][:faultstring]
        return { valid: false } if fault == 'INVALID_INPUT'

        { error: fault_to_error(fault) }
      end

      FAULTS = {
        'SERVICE_UNAVAILABLE' => ServiceUnavailable,
        'MS_UNAVAILABLE' => MemberStateUnavailable,
        'INVALID_REQUESTER_INFO' => InvalidRequester,
        'TIMEOUT' => Timeout,
        'VAT_BLOCKED' => BlockedError,
        'IP_BLOCKED' => BlockedError,
        'GLOBAL_MAX_CONCURRENT_REQ' => RateLimitError,
        'GLOBAL_MAX_CONCURRENT_REQ_TIME' => RateLimitError,
        'MS_MAX_CONCURRENT_REQ' => RateLimitError,
        'MS_MAX_CONCURRENT_REQ_TIME' => RateLimitError
      }.freeze

      def self.fault_to_error(fault)
        (FAULTS[fault] || UnknownViesError).new(fault)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
valvat-1.1.2 lib/valvat/lookup/fault.rb
valvat-1.1.1 lib/valvat/lookup/fault.rb
valvat-1.1.0 lib/valvat/lookup/fault.rb