Exception: JSONAPI::Exceptions::ValidationErrors

Inherits:
Error
  • Object
show all
Defined in:
lib/jsonapi/exceptions.rb

Instance Attribute Summary collapse

Attributes inherited from Error

#error_object_overrides

Instance Method Summary collapse

Methods inherited from Error

#create_error_object

Constructor Details

#initialize(resource, error_object_overrides = {}) ⇒ ValidationErrors

Returns a new instance of ValidationErrors.



453
454
455
456
457
458
459
460
# File 'lib/jsonapi/exceptions.rb', line 453

def initialize(resource, error_object_overrides = {})
  @error_messages = resource.model_error_messages
  @error_metadata = resource.
  @resource_class = resource.class
  @resource_relationships = resource.class._relationships.keys
  @key_formatter = JSONAPI.configuration.key_formatter
  super(error_object_overrides)
end

Instance Attribute Details

#error_messagesObject (readonly)

Returns the value of attribute error_messages.



451
452
453
# File 'lib/jsonapi/exceptions.rb', line 451

def error_messages
  @error_messages
end

#error_metadataObject (readonly)

Returns the value of attribute error_metadata.



451
452
453
# File 'lib/jsonapi/exceptions.rb', line 451

def 
  @error_metadata
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



451
452
453
# File 'lib/jsonapi/exceptions.rb', line 451

def resource_class
  @resource_class
end

#resource_relationshipsObject (readonly)

Returns the value of attribute resource_relationships.



451
452
453
# File 'lib/jsonapi/exceptions.rb', line 451

def resource_relationships
  @resource_relationships
end

Instance Method Details

#errorsObject



466
467
468
469
470
# File 'lib/jsonapi/exceptions.rb', line 466

def errors
  error_messages.flat_map do |attr_key, messages|
    messages.map { |message| json_api_error(attr_key, message) }
  end
end

#format_key(key) ⇒ Object



462
463
464
# File 'lib/jsonapi/exceptions.rb', line 462

def format_key(key)
  @key_formatter.format(key)
end