Class: SBF::Client::ErrorEntity

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

Direct Known Subclasses

ApiErrorEntity

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.



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

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.



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

def code
  @code
end

#detailsObject (readonly)

Returns the value of attribute details.



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

def details
  @details
end

#fieldsObject (readonly)

Returns the value of attribute fields.



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

def fields
  @fields
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#empty?Boolean

Returns:



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

def empty?
  [@code, @type, @details].all?(&:nil?) && @fields.empty?
end

#to_hashObject



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

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

#to_json(*a) ⇒ Object



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

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

#to_sObject



36
37
38
39
40
# File 'lib/stbaldricks/entities/lib/error.rb', line 36

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