Exception: Raas::RaasClientException

Inherits:
APIException
  • Object
show all
Defined in:
lib/raas/exceptions/raas_client_exception.rb

Instance Attribute Summary collapse

Attributes inherited from APIException

#context, #response_code

Instance Method Summary collapse

Constructor Details

#initialize(reason, context) ⇒ RaasClientException

The constructor.

Parameters:

  • The (String)

    reason for raising an exception

  • The (HttpContext)

    HttpContext of the API call.



33
34
35
36
37
38
39
40
# File 'lib/raas/exceptions/raas_client_exception.rb', line 33

def initialize(reason, context)
  super(reason, context)
  begin
    hash = APIHelper.json_deserialize(@context.response.raw_body)
    unbox(hash)
  rescue TypeError
  end
end

Instance Attribute Details

#errorsList of RaasClientErrorModel

An array of errors

Returns:



28
29
30
# File 'lib/raas/exceptions/raas_client_exception.rb', line 28

def errors
  @errors
end

#http_codeInteger

HTTP Code

Returns:

  • (Integer)


20
21
22
# File 'lib/raas/exceptions/raas_client_exception.rb', line 20

def http_code
  @http_code
end

#http_phraseString

HTTP Phrase

Returns:



24
25
26
# File 'lib/raas/exceptions/raas_client_exception.rb', line 24

def http_phrase
  @http_phrase
end

#pathString

Request Path

Returns:



16
17
18
# File 'lib/raas/exceptions/raas_client_exception.rb', line 16

def path
  @path
end

#request_idString

Request ID

Returns:



12
13
14
# File 'lib/raas/exceptions/raas_client_exception.rb', line 12

def request_id
  @request_id
end

#timestampDateTime

Request timestamp

Returns:

  • (DateTime)


8
9
10
# File 'lib/raas/exceptions/raas_client_exception.rb', line 8

def timestamp
  @timestamp
end

Instance Method Details

#unbox(hash) ⇒ Object

Populates this object by extracting properties from a hash.

Parameters:

  • The (Hash)

    deserialized response sent by the server in the response body.



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/raas/exceptions/raas_client_exception.rb', line 44

def unbox(hash)
  @timestamp = DateTime.rfc3339(hash['timestamp']) if hash['timestamp']
  @request_id = hash['requestId']
  @path = hash['path']
  @http_code = hash['httpCode']
  @http_phrase = hash['httpPhrase']
  # Parameter is an array, so we need to iterate through it
  @errors = nil
  if hash['errors'] != nil
    @errors = Array.new
    hash['errors'].each{|structure| @errors << (RaasClientErrorModel.from_hash(structure) if structure)}
  end
end