Exception: HumanError::Errors::ResourcePersistenceError

Inherits:
RuntimeError
  • Object
show all
Includes:
HumanError::Error, CrudError
Defined in:
lib/human_error/errors/crud_errors/resource_persistence_error.rb

Instance Attribute Summary collapse

Attributes included from CrudError

#action, #resource_id, #resource_name

Attributes included from HumanError::Error

#code, #developer_documentation_url, #external_documentation_url, #id, #message

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CrudError

#initialize

Methods included from HumanError::Error

#as_json, included, #initialize, #to_json, #to_s

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



9
10
11
# File 'lib/human_error/errors/crud_errors/resource_persistence_error.rb', line 9

def attributes
  @attributes
end

#errorsObject

Returns the value of attribute errors.



9
10
11
# File 'lib/human_error/errors/crud_errors/resource_persistence_error.rb', line 9

def errors
  @errors
end

Class Method Details

.convert(original_error, overrides = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/human_error/errors/crud_errors/resource_persistence_error.rb', line 12

def self.convert(original_error, overrides = {})
  initialization_parameters = {}

  case original_error.class.name
  when 'ActiveRecord::RecordInvalid',
       'ActiveRecord::RecordNotSaved'

    initialization_parameters = {
      attributes: original_error.record.attributes,
      errors:     original_error.record.errors.full_messages,
    }
  end

  new(initialization_parameters.merge(overrides))
end

Instance Method Details

#detailObject



36
37
38
39
# File 'lib/human_error/errors/crud_errors/resource_persistence_error.rb', line 36

def detail
  "One or more of the attributes on the #{resource_name} you attempted " \
  "to #{action} is invalid."
end

#http_statusObject



28
29
30
# File 'lib/human_error/errors/crud_errors/resource_persistence_error.rb', line 28

def http_status
  422
end

#sourceObject



41
42
43
44
45
46
# File 'lib/human_error/errors/crud_errors/resource_persistence_error.rb', line 41

def source
  {
    'errors'     => errors,
    'attributes' => attributes,
  }
end

#titleObject



32
33
34
# File 'lib/human_error/errors/crud_errors/resource_persistence_error.rb', line 32

def title
  'Resource Persistence Error'
end