Exception: Cryptohopper::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/cryptohopper/errors.rb

Overview

Single exception raised by every SDK call on non-2xx responses (and on network/timeout failures). Unknown server codes pass through as-is on ‘#code` so callers can handle new codes without waiting for an SDK update.

Constant Summary collapse

KNOWN_CODES =
%w[
  VALIDATION_ERROR
  UNAUTHORIZED
  FORBIDDEN
  NOT_FOUND
  CONFLICT
  RATE_LIMITED
  SERVER_ERROR
  SERVICE_UNAVAILABLE
  DEVICE_UNAUTHORIZED
  NETWORK_ERROR
  TIMEOUT
  UNKNOWN
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, message:, status:, server_code: nil, ip_address: nil, retry_after_ms: nil) ⇒ Error

Returns a new instance of Error.



26
27
28
29
30
31
32
33
34
# File 'lib/cryptohopper/errors.rb', line 26

def initialize(code:, message:, status:, server_code: nil, ip_address: nil,
               retry_after_ms: nil)
  super(message)
  @code = code
  @status = status
  @server_code = server_code
  @ip_address = ip_address
  @retry_after_ms = retry_after_ms
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



24
25
26
# File 'lib/cryptohopper/errors.rb', line 24

def code
  @code
end

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



24
25
26
# File 'lib/cryptohopper/errors.rb', line 24

def ip_address
  @ip_address
end

#retry_after_msObject (readonly)

Returns the value of attribute retry_after_ms.



24
25
26
# File 'lib/cryptohopper/errors.rb', line 24

def retry_after_ms
  @retry_after_ms
end

#server_codeObject (readonly)

Returns the value of attribute server_code.



24
25
26
# File 'lib/cryptohopper/errors.rb', line 24

def server_code
  @server_code
end

#statusObject (readonly)

Returns the value of attribute status.



24
25
26
# File 'lib/cryptohopper/errors.rb', line 24

def status
  @status
end

Instance Method Details

#inspectObject



36
37
38
39
40
41
42
43
# File 'lib/cryptohopper/errors.rb', line 36

def inspect
  extras = []
  extras << "server_code=#{@server_code}" if @server_code
  extras << "ip=#{@ip_address}" if @ip_address
  extras << "retry_after_ms=#{@retry_after_ms}" if @retry_after_ms
  extra = extras.empty? ? "" : " (#{extras.join(", ")})"
  "#<Cryptohopper::Error code=#{@code} status=#{@status}#{extra}: #{message}>"
end