Class: LoyaltyApIs::CommonErrorException

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

Overview

Common Error class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, response) ⇒ CommonErrorException

The constructor.

Parameters:

  • reason (String)

    The reason for raising an exception.

  • response (HttpResponse)

    The HttpReponse of the API call.



68
69
70
71
72
# File 'lib/loyalty_ap_is/exceptions/common_error_exception.rb', line 68

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

Instance Attribute Details

#errorErrorBaseContainer

Custom error message
Note: One of the following values will be returned:

- Offer does not exist
- Customer does not exist
- Valid from date is invalid
- ValidityPeriod is invalid
- Offer is by default assigned to all customers, which cannot be

changed.

  • Assignment is not allowed
  • Customer assign should have validity dates.
  • Customer assign validity start date should be before the validity end date.
  • Customer assign validity dates must be between the offer assignable dates.
  • Offer validity start date should not be in the past.
  • Customer already assigned to this offer.
  • Offer module is disabled
  • Partner code is not valid for this offer
  • Reference ID already used
  • Partner assignment already ended for this customer

Returns:



63
64
65
# File 'lib/loyalty_ap_is/exceptions/common_error_exception.rb', line 63

def error
  @error
end

#error_codeFloat

custom error code for developer or user Note: One of the following values will be returned: 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1009, 1010, 1011, 1012, 1014, 1015, 1016

Returns:

  • (Float)


17
18
19
# File 'lib/loyalty_ap_is/exceptions/common_error_exception.rb', line 17

def error_code
  @error_code
end

#messageString

Custom error message
Note: One of the following values will be returned:

- Offer does not exist
- Customer does not exist
- Valid from date is invalid
- ValidityPeriod is invalid
- Offer is by default assigned to all customers, which cannot be

changed.

  • Assignment is not allowed
  • Customer assign should have validity dates.
  • Customer assign validity start date should be before the validity end date.
  • Customer assign validity dates must be between the offer assignable dates.
  • Offer validity start date should not be in the past.
  • Customer already assigned to this offer.
  • Offer module is disabled
  • Partner code is not valid for this offer
  • Reference ID already used
  • Partner assignment already ended for this customer

Returns:

  • (String)


40
41
42
# File 'lib/loyalty_ap_is/exceptions/common_error_exception.rb', line 40

def message
  @message
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



92
93
94
95
96
# File 'lib/loyalty_ap_is/exceptions/common_error_exception.rb', line 92

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

#to_sObject

Provides a human-readable string representation of the object.



86
87
88
89
# File 'lib/loyalty_ap_is/exceptions/common_error_exception.rb', line 86

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



77
78
79
80
81
82
83
# File 'lib/loyalty_ap_is/exceptions/common_error_exception.rb', line 77

def unbox(hash)
  return nil unless hash

  @error_code = hash.key?('errorCode') ? hash['errorCode'] : nil
  @message = hash.key?('message') ? hash['message'] : nil
  @error = ErrorBaseContainer.from_hash(hash['error']) if hash['error']
end