Exception: Bitget::Error

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/Bitget/Error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/Bitget/Error.rb', line 8

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/Bitget/Error.rb', line 8

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/Bitget/Error.rb', line 8

def message
  @message
end

Instance Method Details

#error_codeObject

Bitget answers most errors with a JSON body carrying its own code and message, which are more use than the HTTP ones. Not all of them: a 418 arrives with an empty body and there is nothing to parse. Where the body says nothing the HTTP code and message answer instead, so that an error renders as something rather than as a pair of blanks.



18
19
20
# File 'lib/Bitget/Error.rb', line 18

def error_code
  @parsed_body['code'] || @code
end

#error_messageObject



22
23
24
# File 'lib/Bitget/Error.rb', line 22

def error_message
  @parsed_body['msg'] || @parsed_body['message'] || @message
end

#to_sObject



26
27
28
# File 'lib/Bitget/Error.rb', line 26

def to_s
  "Bitget::Error: #{error_code} - #{error_message}"
end