human_error 2.0.0beta5 → 2.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.
- checksums.yaml +4 -4
- data/lib/human_error/rescuable_resource.rb +10 -5
- data/lib/human_error/verifiable_model.rb +10 -9
- data/lib/human_error/version.rb +1 -1
- data/lib/human_error.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17aba5f28df14fa69f37785ddb08659985741d9b
|
4
|
+
data.tar.gz: a39be0f21794151eaebf056663e327b3499b3b91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88747c7a2352b0cdd2d7b9867c481f033b987f353b1af78faa649ebfeb6c015dc23fdf2b0b550eb01e63e0710d397549da10857ab72d85395ea28a2ca97bd8ec
|
7
|
+
data.tar.gz: 1d4b15fbb41d93ed4eb13854d21d39535a7a402ecbbcb66b4fd4c9504ebcd656534efd3ba2081214539d0832bcf0cd5ed3eccfc1350d135a8c29e1ca70b75ce7
|
@@ -7,14 +7,14 @@ module RescuableResource
|
|
7
7
|
module ClassMethods
|
8
8
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Style/GuardClause
|
9
9
|
def rescue_resource(resource_name, from:, via:)
|
10
|
-
|
11
|
-
lookup_library
|
10
|
+
nice_resource_name = resource_name.humanize.downcase
|
11
|
+
lookup_library = via
|
12
12
|
|
13
13
|
if from.include? 'persistence'
|
14
14
|
rescue_from 'ActiveRecord::RecordInvalid',
|
15
15
|
'ActiveRecord::RecordNotSaved' do |exception|
|
16
16
|
human_error = lookup_library.convert(exception,
|
17
|
-
resource_name:
|
17
|
+
resource_name: nice_resource_name,
|
18
18
|
action: action_name)
|
19
19
|
|
20
20
|
render json: human_error,
|
@@ -25,7 +25,7 @@ module RescuableResource
|
|
25
25
|
if from.include? 'not_found'
|
26
26
|
rescue_from 'ActiveRecord::RecordNotFound' do |exception|
|
27
27
|
human_error = lookup_library.convert(exception,
|
28
|
-
resource_name:
|
28
|
+
resource_name: nice_resource_name,
|
29
29
|
action: action_name)
|
30
30
|
|
31
31
|
render json: human_error,
|
@@ -36,13 +36,18 @@ module RescuableResource
|
|
36
36
|
if from.include? 'association'
|
37
37
|
rescue_from 'ActiveRecord::InvalidForeignKey' do |exception|
|
38
38
|
human_error = lookup_library.convert(exception,
|
39
|
-
resource_name:
|
39
|
+
resource_name: nice_resource_name,
|
40
40
|
action: action_name)
|
41
41
|
|
42
42
|
render json: human_error,
|
43
43
|
status: human_error.http_status
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
rescue_from 'HumanError::Error' do |exception|
|
48
|
+
render json: exception,
|
49
|
+
status: exception.http_status
|
50
|
+
end
|
46
51
|
end
|
47
52
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Style/GuardClause
|
48
53
|
end
|
@@ -1,20 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module HumanError
|
1
|
+
class HumanError
|
4
2
|
module VerifiableModel
|
5
3
|
module ClassMethods
|
6
|
-
def verify_model_exists(model_name = nil, options = {})
|
7
|
-
exceptions
|
4
|
+
def verify_model_exists(model_name = nil, options = {}, via: HumanError.new)
|
5
|
+
exceptions = options[:except] || %i{create index}
|
6
|
+
lookup_library = via
|
8
7
|
model_name ||= name[/::(\w+)Controller\z/, 1].
|
9
|
-
|
10
|
-
|
8
|
+
singularize.
|
9
|
+
downcase
|
11
10
|
|
12
11
|
before_action except: exceptions do
|
13
12
|
model = public_send(model_name)
|
14
13
|
|
15
|
-
resource_not_found_error =
|
14
|
+
resource_not_found_error = lookup_library.build(
|
15
|
+
'ResourceNotFoundError',
|
16
16
|
resource_name: model_name,
|
17
|
-
resource_id: params[:id],
|
17
|
+
resource_id: [params[:id]],
|
18
|
+
action: action_name,
|
18
19
|
)
|
19
20
|
|
20
21
|
fail resource_not_found_error unless model.persisted?
|
data/lib/human_error/version.rb
CHANGED
data/lib/human_error.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'human_error/version'
|
2
2
|
require 'human_error/error'
|
3
3
|
require 'human_error/errors'
|
4
|
+
require 'human_error/rescuable_resource'
|
5
|
+
require 'human_error/verifiable_model'
|
4
6
|
|
5
7
|
class HumanError
|
6
8
|
attr_accessor :configuration
|
@@ -36,8 +38,6 @@ class HumanError
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def raise(error_type, **args)
|
39
|
-
|
40
|
-
|
41
|
-
Kernel.raise error
|
41
|
+
Kernel.raise build(error_type, **args)
|
42
42
|
end
|
43
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jfelchner
|
@@ -106,9 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
111
|
+
version: '0'
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
114
|
rubygems_version: 2.4.6
|