human_error 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/human_error.rb +21 -19
  3. data/lib/human_error/configuration.rb +27 -7
  4. data/lib/human_error/error.rb +60 -28
  5. data/lib/human_error/errors/authentication_errors/duplicate_authentication_error.rb +8 -8
  6. data/lib/human_error/errors/authentication_errors/invalid_token_error.rb +8 -8
  7. data/lib/human_error/errors/authentication_errors/invalid_username_or_password_error.rb +8 -8
  8. data/lib/human_error/errors/crud_errors/association_error.rb +8 -9
  9. data/lib/human_error/errors/crud_errors/resource_not_found_error.rb +8 -8
  10. data/lib/human_error/errors/crud_errors/resource_persistence_error.rb +8 -8
  11. data/lib/human_error/errors/request_errors/parameter_missing_error.rb +40 -0
  12. data/lib/human_error/errors/request_errors/unpermitted_parameters_error.rb +46 -0
  13. data/lib/human_error/rescuable_resource.rb +30 -47
  14. data/lib/human_error/verifiable_resource.rb +36 -0
  15. data/lib/human_error/version.rb +1 -1
  16. data/spec/lib/human_error/configuration_spec.rb +13 -26
  17. data/spec/lib/human_error/error_spec.rb +135 -1
  18. data/spec/lib/human_error/errors/authentication_errors/duplicate_authentication_error_spec.rb +8 -13
  19. data/spec/lib/human_error/errors/authentication_errors/invalid_token_error_spec.rb +8 -12
  20. data/spec/lib/human_error/errors/authentication_errors/invalid_username_or_password_error_spec.rb +8 -13
  21. data/spec/lib/human_error/errors/crud_errors/association_error_spec.rb +8 -16
  22. data/spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb +9 -17
  23. data/spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb +9 -17
  24. data/spec/lib/human_error/errors/request_errors/parameter_missing_error_spec.rb +55 -0
  25. data/spec/lib/human_error/errors/request_errors/unpermitted_parameters_error_spec.rb +62 -0
  26. data/spec/lib/human_error_spec.rb +4 -57
  27. metadata +26 -12
  28. data/lib/human_error/error_code_directory.rb +0 -20
  29. data/lib/human_error/errors.rb +0 -9
  30. data/lib/human_error/errors/request_error.rb +0 -48
  31. data/lib/human_error/knowledgebase_id_directory.rb +0 -20
  32. data/lib/human_error/verifiable_model.rb +0 -30
  33. data/spec/lib/human_error/errors/request_error_spec.rb +0 -95
@@ -1,20 +0,0 @@
1
- class HumanError
2
- class ErrorCodeDirectory
3
- def self.lookup(error_class)
4
- directory[error_class]
5
- end
6
-
7
- def self.directory
8
- {
9
- 'HumanError::Errors::InvalidTokenError' => 1003,
10
- 'HumanError::Errors::InvalidUsernameOrPasswordError' => 1004,
11
- 'HumanError::Errors::ResourceNotFoundError' => 1005,
12
- 'HumanError::Errors::ResourcePersistenceError' => 1006,
13
- 'Apill::Errors::InvalidApiRequestError' => 1007,
14
- 'HumanError::Errors::DuplicateAuthenticationError' => 1008,
15
- 'HumanError::Errors::AssociationError' => 1009,
16
- 'Apill::Errors::InvalidSubdomainError' => 1010,
17
- }
18
- end
19
- end
20
- end
@@ -1,9 +0,0 @@
1
- require 'human_error/errors/request_error'
2
- require 'human_error/errors/authentication_error'
3
- require 'human_error/errors/authentication_errors/invalid_token_error'
4
- require 'human_error/errors/authentication_errors/invalid_username_or_password_error'
5
- require 'human_error/errors/authentication_errors/duplicate_authentication_error'
6
- require 'human_error/errors/crud_error'
7
- require 'human_error/errors/crud_errors/resource_not_found_error'
8
- require 'human_error/errors/crud_errors/resource_persistence_error'
9
- require 'human_error/errors/crud_errors/association_error'
@@ -1,48 +0,0 @@
1
- require 'human_error/error'
2
- require 'human_error/utilities/string'
3
-
4
- class HumanError
5
- module Errors
6
- class RequestError < RuntimeError
7
- include HumanError::Error
8
-
9
- attr_accessor :http_status,
10
- :developer_message,
11
- :developer_details,
12
- :friendly_message
13
-
14
- def as_json(_options = {})
15
- {
16
- error: {
17
- status: http_status,
18
- code: code,
19
- developer_documentation_uri: developer_documentation_uri,
20
- customer_support_uri: customer_support_uri,
21
- developer_message_key: developer_message_key,
22
- developer_message: developer_message,
23
- developer_details: developer_details,
24
- friendly_message_key: friendly_message_key,
25
- friendly_message: friendly_message,
26
- },
27
- }
28
- end
29
-
30
- private
31
-
32
- def developer_message_key
33
- "#{base_message_key}.developer"
34
- end
35
-
36
- def friendly_message_key
37
- "#{base_message_key}.friendly"
38
- end
39
-
40
- def base_message_key
41
- HumanError::Utilities::String.
42
- underscore(self.class.name).
43
- gsub(%r{\A[^/]+/}, '').
44
- gsub(%r{[_/]}, '.')
45
- end
46
- end
47
- end
48
- end
@@ -1,20 +0,0 @@
1
- class HumanError
2
- class KnowledgebaseIdDirectory
3
- def self.lookup(error_class)
4
- directory[error_class]
5
- end
6
-
7
- def self.directory
8
- {
9
- 'HumanError::Errors::InvalidTokenError' => '1234567890',
10
- 'HumanError::Errors::InvalidUsernameOrPasswordError' => '1234567890',
11
- 'HumanError::Errors::ResourceNotFoundError' => '1234567890',
12
- 'HumanError::Errors::ResourcePersistenceError' => '1234567890',
13
- 'Apill::Errors::InvalidApiRequestError' => '1234567890',
14
- 'HumanError::Errors::DuplicateAuthenticationError' => '1234567890',
15
- 'HumanError::Errors::AssociationError' => '1234567890',
16
- 'Apill::Errors::InvalidSubdomainError' => '1234567890',
17
- }
18
- end
19
- end
20
- end
@@ -1,30 +0,0 @@
1
- class HumanError
2
- module VerifiableModel
3
- module ClassMethods
4
- def verify_model_exists(model_name = nil, options = {}, via: HumanError.new)
5
- exceptions = options[:except] || %i{create index}
6
- lookup_library = via
7
- model_name ||= name[/::(\w+)Controller\z/, 1].
8
- singularize.
9
- downcase
10
-
11
- before_action except: exceptions do
12
- model = public_send(model_name)
13
-
14
- resource_not_found_error = lookup_library.build(
15
- 'ResourceNotFoundError',
16
- resource_name: model_name,
17
- resource_id: [params[:id]],
18
- action: action_name,
19
- )
20
-
21
- fail resource_not_found_error unless model.persisted?
22
- end
23
- end
24
- end
25
-
26
- def self.included(base)
27
- base.extend ClassMethods
28
- end
29
- end
30
- end
@@ -1,95 +0,0 @@
1
- require 'rspectacular'
2
- require 'human_error/errors/request_error'
3
-
4
- class HumanError
5
- module Errors
6
- describe RequestError do
7
- it 'can generate error data' do
8
- request_error = RequestError.new(
9
- http_status: 'flibbity',
10
- code: 'jibbit',
11
- developer_message: 'I cannot receive any satisfaction',
12
- developer_details: 'But perhaps if I attempt it one more time, I can',
13
- friendly_message: 'receive what I need',
14
- knowledgebase_article_id: '87654321',
15
- api_version: 'janky',
16
- api_error_documentation_url: 'asimof',
17
- knowledgebase_url: 'jinkies')
18
-
19
- expect(request_error.as_json).to eql(
20
- error: {
21
- status: 'flibbity',
22
- code: 'jibbit',
23
- developer_documentation_uri: 'asimof/jibbit?version=janky',
24
- customer_support_uri: 'jinkies/87654321',
25
- developer_message_key: 'errors.request.error.developer',
26
- developer_message: 'I cannot receive any satisfaction',
27
- developer_details: 'But perhaps if I attempt it one more time, I can',
28
- friendly_message_key: 'errors.request.error.friendly',
29
- friendly_message: 'receive what I need',
30
- })
31
- end
32
-
33
- it 'can extract configuration from the global config if it is not passed in' do
34
- HumanError.configure do |config|
35
- config.api_version = 'janky'
36
- config.api_error_documentation_url = 'asimof'
37
- config.knowledgebase_url = 'jinkies'
38
- end
39
-
40
- request_error = RequestError.new(
41
- http_status: 'flibbity',
42
- code: 'jibbit',
43
- developer_message: 'I cannot receive any satisfaction',
44
- developer_details: 'But perhaps if I attempt it one more time, I can',
45
- friendly_message: 'receive what I need',
46
- knowledgebase_article_id: '87654321')
47
-
48
- expect(request_error.as_json).to eql(
49
- error: {
50
- status: 'flibbity',
51
- code: 'jibbit',
52
- developer_documentation_uri: 'asimof/jibbit?version=janky',
53
- customer_support_uri: 'jinkies/87654321',
54
- developer_message_key: 'errors.request.error.developer',
55
- developer_message: 'I cannot receive any satisfaction',
56
- developer_details: 'But perhaps if I attempt it one more time, I can',
57
- friendly_message_key: 'errors.request.error.friendly',
58
- friendly_message: 'receive what I need',
59
- })
60
- end
61
-
62
- it 'can override the global config if it is set, but an explicit value is passed in' do
63
- HumanError.configure do |config|
64
- config.api_version = 'janky'
65
- config.api_error_documentation_url = 'asimof'
66
- config.knowledgebase_url = 'jinkies'
67
- end
68
-
69
- request_error = RequestError.new(
70
- http_status: 'flibbity',
71
- code: 'jibbit',
72
- developer_message: 'I cannot receive any satisfaction',
73
- developer_details: 'But perhaps if I attempt it one more time, I can',
74
- friendly_message: 'receive what I need',
75
- knowledgebase_article_id: '87654321',
76
- api_version: 'hanky',
77
- api_error_documentation_url: 'hasimof',
78
- knowledgebase_url: 'hinkies')
79
-
80
- expect(request_error.as_json).to eql(
81
- error: {
82
- status: 'flibbity',
83
- code: 'jibbit',
84
- developer_documentation_uri: 'hasimof/jibbit?version=hanky',
85
- customer_support_uri: 'hinkies/87654321',
86
- developer_message_key: 'errors.request.error.developer',
87
- developer_message: 'I cannot receive any satisfaction',
88
- developer_details: 'But perhaps if I attempt it one more time, I can',
89
- friendly_message_key: 'errors.request.error.friendly',
90
- friendly_message: 'receive what I need',
91
- })
92
- end
93
- end
94
- end
95
- end