Class: SBF::Client::ErrorEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/stbaldricks/entities/lib/error.rb

Constant Summary collapse

BAD_INPUT =
5007

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ ErrorEntity

Returns a new instance of ErrorEntity.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stbaldricks/entities/lib/error.rb', line 10

def initialize(data = {})
  super()

  # In case null was explicitly passed in
  data ||= {}

  # Set all attributes
  @code = data[:code].freeze
  @type = data[:type].freeze
  @details = data[:details].freeze
  @fields = Set.new(data[:errors].empty? ? [] : data[:errors]).freeze
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/stbaldricks/entities/lib/error.rb', line 8

def code
  @code
end

#detailsObject (readonly)

Returns the value of attribute details.



8
9
10
# File 'lib/stbaldricks/entities/lib/error.rb', line 8

def details
  @details
end

#fieldsObject (readonly)

Returns the value of attribute fields.



8
9
10
# File 'lib/stbaldricks/entities/lib/error.rb', line 8

def fields
  @fields
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/stbaldricks/entities/lib/error.rb', line 8

def type
  @type
end

Instance Method Details

#to_hashObject



23
24
25
# File 'lib/stbaldricks/entities/lib/error.rb', line 23

def to_hash
  {code: @code, type: @type, details: @details, fields: @fields.to_a}
end

#to_json(*a) ⇒ Object



27
28
29
# File 'lib/stbaldricks/entities/lib/error.rb', line 27

def to_json(*a)
  to_hash.to_json(*a)
end

#to_sObject



31
32
33
34
35
# File 'lib/stbaldricks/entities/lib/error.rb', line 31

def to_s
  error_message = "#{@code} - [#{@type}] #{@details}"
  error_message << " details: #{@fields.to_a.join(', ')}" unless @fields.empty?
  error_message
end