Exception: HumanError::Errors::ResourceNotFoundError

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

Instance Attribute Summary

Attributes included from CrudError

#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

Class Method Details

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



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

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

  case original_error.class.name
  when 'ActiveRecord::RecordNotFound'
    initialization_parameters = {
      resource_id: case original_error.message
                   when /\ACouldn't find .* without an ID\z/
                     []
                   when /\ACouldn't find .* with \'.*\'=([a-f0-9\-]+)/
                     [Regexp.last_match(1)]
                   when /\ACouldn't find all .* with \'.*\': ((?:[a-f0-9\-]+(?:, )?)+)/
                     Array(Regexp.last_match(1).split(', '))
                   end,
    }
  end

  new(initialization_parameters.merge(overrides))
end

Instance Method Details

#actionObject



46
47
48
# File 'lib/human_error/errors/crud_errors/resource_not_found_error.rb', line 46

def action
  @action || 'access'
end

#detailObject



37
38
39
40
# File 'lib/human_error/errors/crud_errors/resource_not_found_error.rb', line 37

def detail
  "The #{resource_name} you attempted to #{action} for this request is either " \
  'not authorized for the authenticated user or does not exist.'
end

#http_statusObject



29
30
31
# File 'lib/human_error/errors/crud_errors/resource_not_found_error.rb', line 29

def http_status
  404
end

#sourceObject



42
43
44
# File 'lib/human_error/errors/crud_errors/resource_not_found_error.rb', line 42

def source
  { "#{resource_name_underscored}_id" => resource_id }
end

#titleObject



33
34
35
# File 'lib/human_error/errors/crud_errors/resource_not_found_error.rb', line 33

def title
  'Resource Not Found'
end