Class: WalmartApIs::ErrorErrorException

Inherits:
APIException
  • Object
show all
Defined in:
lib/walmart_ap_is/exceptions/error_error_exception.rb

Overview

Error response returned when the request is unsuccessful.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, response) ⇒ ErrorErrorException

The constructor.

Parameters:

  • reason (String)

    The reason for raising an exception.

  • response (HttpResponse)

    The HttpReponse of the API call.



27
28
29
30
31
# File 'lib/walmart_ap_is/exceptions/error_error_exception.rb', line 27

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

Instance Attribute Details

#codeString

An error code that identifies the type of error that occurred.

Returns:

  • (String)


14
15
16
# File 'lib/walmart_ap_is/exceptions/error_error_exception.rb', line 14

def code
  @code
end

#detailsString

Additional details that can help the caller understand or fix the issue.

Returns:

  • (String)


22
23
24
# File 'lib/walmart_ap_is/exceptions/error_error_exception.rb', line 22

def details
  @details
end

#messageString

A message that describes the error condition.

Returns:

  • (String)


18
19
20
# File 'lib/walmart_ap_is/exceptions/error_error_exception.rb', line 18

def message
  @message
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



51
52
53
54
55
# File 'lib/walmart_ap_is/exceptions/error_error_exception.rb', line 51

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} code: #{@code.inspect}, message: #{@message.inspect}, details:"\
  " #{@details.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



45
46
47
48
# File 'lib/walmart_ap_is/exceptions/error_error_exception.rb', line 45

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} code: #{@code}, message: #{@message}, details: #{@details}>"
end

#unbox(hash) ⇒ Object

Populates this object by extracting properties from a hash. response body.

Parameters:

  • hash (Hash)

    The deserialized response sent by the server in the



36
37
38
39
40
41
42
# File 'lib/walmart_ap_is/exceptions/error_error_exception.rb', line 36

def unbox(hash)
  return nil unless hash

  @code = hash.key?('code') ? hash['code'] : nil
  @message = hash.key?('message') ? hash['message'] : nil
  @details = hash.key?('details') ? hash['details'] : SKIP
end