Class: Batches::Batches400ErrorException

Inherits:
APIException
  • Object
show all
Defined in:
lib/batches/exceptions/batches400_error_exception.rb

Overview

Bad Request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, response) ⇒ Batches400ErrorException

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/batches/exceptions/batches400_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

#detailed_error_codeDetailedErrorCode

Unique reference to identify the error.

Returns:



18
19
20
# File 'lib/batches/exceptions/batches400_error_exception.rb', line 18

def detailed_error_code
  @detailed_error_code
end

#detailed_error_descriptionString

Unique Text describing the specific error.

Returns:

  • (String)


22
23
24
# File 'lib/batches/exceptions/batches400_error_exception.rb', line 22

def detailed_error_description
  @detailed_error_description
end

#error_codeErrorCode

This indicates an issue with the API request.

Returns:



14
15
16
# File 'lib/batches/exceptions/batches400_error_exception.rb', line 14

def error_code
  @error_code
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



54
55
56
57
58
59
# File 'lib/batches/exceptions/batches400_error_exception.rb', line 54

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

#to_sObject

Provides a human-readable string representation of the object.



47
48
49
50
51
# File 'lib/batches/exceptions/batches400_error_exception.rb', line 47

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} error_code: #{@error_code}, detailed_error_code: #{@detailed_error_code},"\
  " detailed_error_description: #{@detailed_error_description}>"
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
43
44
# File 'lib/batches/exceptions/batches400_error_exception.rb', line 36

def unbox(hash)
  return nil unless hash

  @error_code = hash.key?('error_code') ? hash['error_code'] : SKIP
  @detailed_error_code =
    hash.key?('detailed_error_code') ? hash['detailed_error_code'] : SKIP
  @detailed_error_description =
    hash.key?('detailed_error_description') ? hash['detailed_error_description'] : SKIP
end