Exception: Common::Exceptions::DetailedSchemaErrors

Inherits:
BaseError
  • Object
show all
Defined in:
lib/common/exceptions/detailed_schema_errors.rb

Instance Method Summary collapse

Methods inherited from BaseError

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

Constructor Details

#initialize(raw_schema_errors) ⇒ DetailedSchemaErrors

Expects array of JSONSchemer errors

Raises:

  • (TypeError)


10
11
12
13
# File 'lib/common/exceptions/detailed_schema_errors.rb', line 10

def initialize(raw_schema_errors)
  @raw_errors = raw_schema_errors
  raise TypeError, 'the resource provided has no errors' if raw_schema_errors.blank?
end

Instance Method Details

#errorsObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/common/exceptions/detailed_schema_errors.rb', line 15

def errors
  @errors ||= @raw_errors.map do |raw_error|
    type = raw_error['type'].downcase
    pointer = raw_error['data_pointer'].presence || '/'
    error = if respond_to?(type, true)
              send type, raw_error
            else
              I18n.t('common.exceptions.validation_errors')
            end
    SerializableError.new error.merge source: { pointer: }
  end
end