Sha256: 0ee0b101942a44a7cb8f06b98b8da8cc2842c535a39d60eb5309de421a1f2c8a

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

class Valvat
  class Lookup
    class Fault < Response
      def to_hash
        @to_hash ||= case @raw
                     when Savon::HTTPError
                       { error: HTTPError.new(nil, @raw) }
                     when Savon::UnknownOperationError
                       { error: OperationUnknown.new(nil, @raw) }
                     else
                       soap_fault
                     end
      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

      private

      def soap_fault
        fault = @raw.to_hash[:fault][:faultstring]

        if fault == 'INVALID_INPUT'
          { valid: false }
        else
          error = (FAULTS[fault] || UnknownViesError).new(fault)
          { error: error }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
valvat-1.1.5 lib/valvat/lookup/fault.rb