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.



456
457
458
459
460
461
462
# File 'lib/jsonapi/exceptions.rb', line 456

def initialize(resource, error_object_overrides = {})
  @error_messages = resource.model_error_messages
  @error_metadata = resource.
  @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.



454
455
456
# File 'lib/jsonapi/exceptions.rb', line 454

def error_messages
  @error_messages
end

#error_metadataObject (readonly)

Returns the value of attribute error_metadata.



454
455
456
# File 'lib/jsonapi/exceptions.rb', line 454

def 
  @error_metadata
end

#resource_relationshipsObject (readonly)

Returns the value of attribute resource_relationships.



454
455
456
# File 'lib/jsonapi/exceptions.rb', line 454

def resource_relationships
  @resource_relationships
end

Instance Method Details

#errorsObject



468
469
470
471
472
# File 'lib/jsonapi/exceptions.rb', line 468

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



464
465
466
# File 'lib/jsonapi/exceptions.rb', line 464

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