Exception: TSJSON::ListValidationError

Inherits:
ValidationError show all
Defined in:
lib/errors/list_validation_error.rb

Instance Method Summary collapse

Constructor Details

#initialize(errors:) ⇒ ListValidationError

Returns a new instance of ListValidationError.



3
4
5
# File 'lib/errors/list_validation_error.rb', line 3

def initialize(errors:)
  super
end

Instance Method Details

#to_human_jsonObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/errors/list_validation_error.rb', line 19

def to_human_json
  details =
    @details[:errors].map do |err|
      index = err[:index]
      err_human_json = err[:error].to_human_json

      {
        message: "#{index}: #{err_human_json[:message]}",
        details: err_human_json[:details]
      }.compact
    end

  return { message: 'One or more items are invalid', details: details }
end

#to_jsonObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/errors/list_validation_error.rb', line 7

def to_json
  {
    code: self.class.name.split('::').last,
    details: {
      errors:
        @details[:errors].map do |e|
          { index: e[:index], error: e[:error].to_json }
        end
    }
  }
end