Module: Kucoin::Rest::Errors

Included in:
Client
Defined in:
lib/kucoin/rest/errors.rb

Instance Method Summary collapse

Instance Method Details

#error?(response) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kucoin/rest/errors.rb', line 5

def error?(response)
  if response.is_a?(Hash) && (response.has_key?("error") || response.has_key?("code")) 
    status      =   nil
    message     =   nil
    
    if response.has_key?("error")
      error     =   response.fetch("error", nil)
      status    =   response.fetch("status", nil)
      message   =   response.fetch("message", nil)
    elsif response.has_key?("code") && response.fetch("code", nil).eql?("ERROR")
      message   =   response.fetch("msg", nil)
    end
    
    if !message.to_s.empty?
      if status.nil?
        raise ::Kucoin::Errors::ResponseError.new(message)
      else
        ::Kucoin::Errors::MAPPING.fetch(status, nil)&.call
      end
    end
  end
end