Exception: Common::Exceptions::ValidationErrors
- Defined in:
- lib/common/exceptions/validation_errors.rb
Overview
Validation Error - an ActiveModel having validation errors, can be sent to this exception
Direct Known Subclasses
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #error_attributes(key, message, full_message) ⇒ Object private
- #errors ⇒ Object
-
#initialize(resource) ⇒ ValidationErrors
constructor
A new instance of ValidationErrors.
Methods inherited from BaseError
#i18n_data, #i18n_field, #i18n_interpolated, #i18n_key, #log_to_sentry?, #message, #sentry_type, #status_code
Constructor Details
#initialize(resource) ⇒ ValidationErrors
Returns a new instance of ValidationErrors.
12 13 14 15 |
# File 'lib/common/exceptions/validation_errors.rb', line 12 def initialize(resource) @resource = resource raise TypeError, 'the resource provided has no errors' if resource.errors.empty? end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
10 11 12 |
# File 'lib/common/exceptions/validation_errors.rb', line 10 def resource @resource end |
Instance Method Details
#error_attributes(key, message, full_message) ⇒ Object (private)
27 28 29 30 31 32 33 |
# File 'lib/common/exceptions/validation_errors.rb', line 27 def error_attributes(key, , ) i18n_data.merge( title: , detail: "#{key.to_s.underscore.dasherize} - #{}", source: { pointer: "data/attributes/#{key.to_s.underscore.dasherize}" } ) end |
#errors ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/common/exceptions/validation_errors.rb', line 17 def errors @resource.errors.map do |error| = error. attributes = error_attributes(error.attribute, error., ) SerializableError.new(attributes) end end |