Exception: JSONAPI::Exceptions::InvalidRelationship

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(type, relationship_name, error_object_overrides = {}) ⇒ InvalidRelationship

Returns a new instance of InvalidRelationship.



333
334
335
336
337
# File 'lib/jsonapi/exceptions.rb', line 333

def initialize(type, relationship_name, error_object_overrides = {})
  @relationship_name = relationship_name
  @type = type
  super(error_object_overrides)
end

Instance Attribute Details

#relationship_nameObject

Returns the value of attribute relationship_name.



331
332
333
# File 'lib/jsonapi/exceptions.rb', line 331

def relationship_name
  @relationship_name
end

#typeObject

Returns the value of attribute type.



331
332
333
# File 'lib/jsonapi/exceptions.rb', line 331

def type
  @type
end

Instance Method Details

#errorsObject



339
340
341
342
343
344
345
346
347
# File 'lib/jsonapi/exceptions.rb', line 339

def errors
  [create_error_object(code: JSONAPI::INVALID_RELATIONSHIP,
                       status: :bad_request,
                       title: I18n.translate('jsonapi-resources.exceptions.invalid_relationship.title',
                                             default: 'Invalid relationship'),
                       detail: I18n.translate('jsonapi-resources.exceptions.invalid_relationship.detail',
                                              default: "#{relationship_name} is not a valid field for #{type}.",
                                              relationship_name: relationship_name, type: type))]
end