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.



476
477
478
479
480
481
482
483
# File 'lib/jsonapi/exceptions.rb', line 476

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.



474
475
476
# File 'lib/jsonapi/exceptions.rb', line 474

def error_messages
  @error_messages
end

#error_metadataObject (readonly)

Returns the value of attribute error_metadata.



474
475
476
# File 'lib/jsonapi/exceptions.rb', line 474

def 
  @error_metadata
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



474
475
476
# File 'lib/jsonapi/exceptions.rb', line 474

def resource_class
  @resource_class
end

#resource_relationshipsObject (readonly)

Returns the value of attribute resource_relationships.



474
475
476
# File 'lib/jsonapi/exceptions.rb', line 474

def resource_relationships
  @resource_relationships
end

Instance Method Details

#errorsObject



489
490
491
492
493
# File 'lib/jsonapi/exceptions.rb', line 489

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



485
486
487
# File 'lib/jsonapi/exceptions.rb', line 485

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