Exception: Ubicloud::Error

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

Overview

Error class used for errors raised by Ubicloud’s Ruby SDK.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code: nil, body: nil) ⇒ Error

Accept the code and body keyword arguments for metadata related to this error.



22
23
24
25
26
# File 'lib/ubicloud.rb', line 22

def initialize(message, code: nil, body: nil)
  super(message)
  @code = code
  @body = body
end

Instance Attribute Details

#codeObject (readonly)

The integer HTTP status code related to the error. Can be nil if the Error is not related to an HTTP request.



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

def code
  @code
end

Instance Method Details

#paramsObject

A hash of parameters. This is the parsed JSON response body for the request that resulted in an error. If an invalid body is given, or the error is not related to an HTTP request, returns an empty hash.



32
33
34
35
36
# File 'lib/ubicloud.rb', line 32

def params
  @body ? JSON.parse(@body) : {}
rescue
  {}
end