Class: LoyaltyApIs::JsonApiErrorException

Inherits:
APIException
  • Object
show all
Defined in:
lib/loyalty_ap_is/exceptions/json_api_error_exception.rb

Overview

JSON API Error class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, response) ⇒ JsonApiErrorException

The constructor.

Parameters:

  • reason (String)

    The reason for raising an exception.

  • response (HttpResponse)

    The HttpReponse of the API call.



23
24
25
26
27
# File 'lib/loyalty_ap_is/exceptions/json_api_error_exception.rb', line 23

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

Instance Attribute Details

#errorsArray[ErrorItem]

TODO: Write general description for this method

Returns:



18
19
20
# File 'lib/loyalty_ap_is/exceptions/json_api_error_exception.rb', line 18

def errors
  @errors
end

#jsonapiJsonApiVersion

TODO: Write general description for this method

Returns:



14
15
16
# File 'lib/loyalty_ap_is/exceptions/json_api_error_exception.rb', line 14

def jsonapi
  @jsonapi
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



55
56
57
58
# File 'lib/loyalty_ap_is/exceptions/json_api_error_exception.rb', line 55

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} jsonapi: #{@jsonapi.inspect}, errors: #{@errors.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



49
50
51
52
# File 'lib/loyalty_ap_is/exceptions/json_api_error_exception.rb', line 49

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} jsonapi: #{@jsonapi}, errors: #{@errors}>"
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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/loyalty_ap_is/exceptions/json_api_error_exception.rb', line 32

def unbox(hash)
  return nil unless hash

  @jsonapi = JsonApiVersion.from_hash(hash['jsonapi']) if hash['jsonapi']
  # Parameter is an array, so we need to iterate through it
  @errors = nil
  unless hash['errors'].nil?
    @errors = []
    hash['errors'].each do |structure|
      @errors << (ErrorItem.from_hash(structure) if structure)
    end
  end

  @errors = SKIP unless hash.key?('errors')
end