Exception: Bybit::ApiError

Inherits:
Error
  • Object
show all
Defined in:
lib/bybit/error.rb

Overview

Raised when the server returns HTTP 200 + retCode != 0 (the V5 norm), or when a transport-level error is enriched with a Bybit body payload. Accepts either a V5 response Hash (extracts retCode/retMsg/result/time) or a plain String message (used for HTTP-status mapping when the CDN/WAF returns a non-JSON body — e.g. 401/403/429 → AuthError/RateLimitError without a decodable retCode).

Direct Known Subclasses

AuthError, RateLimitError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, http_status: nil) ⇒ ApiError

Returns a new instance of ApiError.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bybit/error.rb', line 32

def initialize(response, http_status: nil)
  @http_status = http_status
  if response.is_a?(Hash)
    @ret_code = response['retCode']
    @ret_msg  = response['retMsg']
    @result   = response['result']
    @time     = response['time']
    super("[#{@ret_code}] #{@ret_msg}")
  else
    super(response.to_s)
  end
end

Instance Attribute Details

#http_statusObject (readonly)

Returns the value of attribute http_status.



30
31
32
# File 'lib/bybit/error.rb', line 30

def http_status
  @http_status
end

#resultObject (readonly)

Returns the value of attribute result.



30
31
32
# File 'lib/bybit/error.rb', line 30

def result
  @result
end

#ret_codeObject (readonly)

Returns the value of attribute ret_code.



30
31
32
# File 'lib/bybit/error.rb', line 30

def ret_code
  @ret_code
end

#ret_msgObject (readonly)

Returns the value of attribute ret_msg.



30
31
32
# File 'lib/bybit/error.rb', line 30

def ret_msg
  @ret_msg
end

#timeObject (readonly)

Returns the value of attribute time.



30
31
32
# File 'lib/bybit/error.rb', line 30

def time
  @time
end