Exception: Common::Exceptions::ValidationErrors

Inherits:
BaseError
  • Object
show all
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

ValidationErrorsBadRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseError

#log_to_sentry?, #message, #sentry_type, #status_code

Constructor Details

#initialize(resource) ⇒ ValidationErrors

Returns a new instance of ValidationErrors.

Raises:

  • (TypeError)


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

#resourceObject (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

#errorsObject



17
18
19
20
21
22
23
# File 'lib/common/exceptions/validation_errors.rb', line 17

def errors
  @resource.errors.map do |error|
    full_message = error.full_message
    attributes = error_attributes(error.attribute, error.message, full_message)
    SerializableError.new(attributes)
  end
end