Exception: TSJSON::ListValidationError
- Inherits:
-
ValidationError
- Object
- StandardError
- ValidationError
- TSJSON::ListValidationError
- Defined in:
- lib/errors/list_validation_error.rb
Instance Method Summary collapse
-
#initialize(errors:) ⇒ ListValidationError
constructor
A new instance of ListValidationError.
- #to_human_json ⇒ Object
- #to_json ⇒ Object
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_json ⇒ Object
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_json ⇒ Object
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 |