erratum 1.0.0 → 1.1.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
- checksums.yaml.gz.sig +0 -0
- data/lib/erratum/error.rb +10 -14
- data/lib/erratum/errors/crud_errors/resource_persistence_error.rb +19 -14
- data/lib/erratum/rescuable_resource.rb +7 -4
- data/lib/erratum/version.rb +1 -1
- data/spec/lib/erratum/error_spec.rb +40 -56
- data/spec/lib/erratum/errors/crud_errors/resource_persistence_error_spec.rb +18 -10
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 982e57d709215c3038efc5bec08ee2c2fe3ec196
|
4
|
+
data.tar.gz: 7bb38ea005d8ca877560a156ae4ee28f897b4741
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5251259e5374837ab0d30bdd78b90345c85c30754efc395b70041a0b785b2412084f631eeed8e912d2af0dd7da2f796fd1574ddd84a5ea71bebb09a9f7adba5f
|
7
|
+
data.tar.gz: 075e5ce7e21137754139f8c67a5afb691a501ad48186e9af9f348c76be4970d25d26cab979596da5f8fe299970f638b9bc346f97fb939db62c0c2a8242b9d5a6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/erratum/error.rb
CHANGED
@@ -31,20 +31,16 @@ module Error
|
|
31
31
|
|
32
32
|
def as_json(_options = {})
|
33
33
|
{
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
detail: detail,
|
45
|
-
source: source,
|
46
|
-
},
|
47
|
-
],
|
34
|
+
id: id,
|
35
|
+
links: {
|
36
|
+
about: external_documentation_url,
|
37
|
+
documentation: developer_documentation_url,
|
38
|
+
},
|
39
|
+
status: http_status,
|
40
|
+
code: code,
|
41
|
+
title: title,
|
42
|
+
detail: detail,
|
43
|
+
source: source,
|
48
44
|
}
|
49
45
|
end
|
50
46
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'erratum/error'
|
2
3
|
require 'erratum/errors/crud_error'
|
3
4
|
|
4
5
|
class Erratum
|
@@ -7,23 +8,26 @@ class ResourcePersistenceError < RuntimeError
|
|
7
8
|
include Error
|
8
9
|
include CrudError
|
9
10
|
|
10
|
-
attr_accessor :
|
11
|
-
:
|
11
|
+
attr_accessor :pointer,
|
12
|
+
:attribute,
|
13
|
+
:value
|
12
14
|
|
13
15
|
def self.convert(original_error, overrides = {})
|
14
|
-
initialization_parameters = {}
|
15
|
-
|
16
16
|
case original_error.class.name
|
17
17
|
when 'ActiveRecord::RecordInvalid',
|
18
18
|
'ActiveRecord::RecordNotSaved'
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
original_error.record.errors.each_with_object([]) do |(attribute, error), errors|
|
21
|
+
initialization_parameters = {
|
22
|
+
attribute: attribute.to_s.camelize(:lower),
|
23
|
+
detail: "#{attribute.to_s.humanize} #{error}",
|
24
|
+
pointer: "/data/attributes/#{attribute}",
|
25
|
+
value: original_error.record.public_send(attribute).to_s,
|
26
|
+
}
|
25
27
|
|
26
|
-
|
28
|
+
errors << new(initialization_parameters.merge(overrides))
|
29
|
+
end
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
def http_status
|
@@ -35,14 +39,15 @@ class ResourcePersistenceError < RuntimeError
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def detail
|
38
|
-
"One or more of the attributes on the #{resource_name} you attempted " \
|
39
|
-
|
42
|
+
@detail || "One or more of the attributes on the #{resource_name} you attempted " \
|
43
|
+
"to #{action} is invalid."
|
40
44
|
end
|
41
45
|
|
42
46
|
def source
|
43
47
|
{
|
44
|
-
'
|
45
|
-
'
|
48
|
+
'pointer' => pointer,
|
49
|
+
'parameter' => attribute,
|
50
|
+
'value' => value,
|
46
51
|
}
|
47
52
|
end
|
48
53
|
end
|
@@ -15,14 +15,17 @@ module RescuableResource
|
|
15
15
|
erratum = Erratum.convert(exception,
|
16
16
|
resource_name: self.class.singular_resource_name,
|
17
17
|
action: action_name)
|
18
|
+
erratum = Array(erratum)
|
18
19
|
|
19
|
-
render json: erratum,
|
20
|
-
status: erratum.http_status
|
20
|
+
render json: Hash['errors' => erratum.as_json],
|
21
|
+
status: erratum.first.http_status
|
21
22
|
end
|
22
23
|
|
23
24
|
base.rescue_from 'Erratum::Error' do |exception|
|
24
|
-
|
25
|
-
|
25
|
+
exception = Array(exception)
|
26
|
+
|
27
|
+
render json: Hash['errors' => exception.as_json],
|
28
|
+
status: exception.first.http_status
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
data/lib/erratum/version.rb
CHANGED
@@ -57,20 +57,16 @@ RSpec.describe Error do
|
|
57
57
|
)
|
58
58
|
|
59
59
|
expect(custom_error.as_json).to eql(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
detail: 'I cannot receive any satisfaction',
|
71
|
-
source: 'But perhaps if I attempt it one more time, I can',
|
72
|
-
},
|
73
|
-
],
|
60
|
+
id: 'identifier',
|
61
|
+
links: {
|
62
|
+
about: 'jinkies/87654321',
|
63
|
+
documentation: 'asimof/jibbit?version=janky',
|
64
|
+
},
|
65
|
+
status: 'flibbity',
|
66
|
+
code: 'jibbit',
|
67
|
+
title: 'roll dem bones and stones',
|
68
|
+
detail: 'I cannot receive any satisfaction',
|
69
|
+
source: 'But perhaps if I attempt it one more time, I can',
|
74
70
|
)
|
75
71
|
end
|
76
72
|
|
@@ -98,20 +94,16 @@ RSpec.describe Error do
|
|
98
94
|
)
|
99
95
|
|
100
96
|
expect(custom_error.as_json).to eql(
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
detail: 'I cannot receive any satisfaction',
|
112
|
-
source: 'But perhaps if I attempt it one more time, I can',
|
113
|
-
},
|
114
|
-
],
|
97
|
+
id: 'identifier',
|
98
|
+
links: {
|
99
|
+
about: 'http://example.com/edu',
|
100
|
+
documentation: 'http://example.com/ddu',
|
101
|
+
},
|
102
|
+
status: 'flibbity',
|
103
|
+
code: 'jibbit',
|
104
|
+
title: 'roll dem bones and stones',
|
105
|
+
detail: 'I cannot receive any satisfaction',
|
106
|
+
source: 'But perhaps if I attempt it one more time, I can',
|
115
107
|
)
|
116
108
|
end
|
117
109
|
|
@@ -141,20 +133,16 @@ RSpec.describe Error do
|
|
141
133
|
)
|
142
134
|
|
143
135
|
expect(custom_error.as_json).to eql(
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
detail: 'I cannot receive any satisfaction',
|
155
|
-
source: 'But perhaps if I attempt it one more time, I can',
|
156
|
-
},
|
157
|
-
],
|
136
|
+
id: 'identifier',
|
137
|
+
links: {
|
138
|
+
about: 'hinkies/87654321',
|
139
|
+
documentation: 'hasimof/jibbit?version=hanky',
|
140
|
+
},
|
141
|
+
status: 'flibbity',
|
142
|
+
code: 'jibbit',
|
143
|
+
title: 'roll dem bones and stones',
|
144
|
+
detail: 'I cannot receive any satisfaction',
|
145
|
+
source: 'But perhaps if I attempt it one more time, I can',
|
158
146
|
)
|
159
147
|
end
|
160
148
|
|
@@ -169,20 +157,16 @@ RSpec.describe Error do
|
|
169
157
|
)
|
170
158
|
|
171
159
|
expect(custom_error.as_json).to eql(
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
detail: 'I cannot receive any satisfaction',
|
183
|
-
source: 'But perhaps if I attempt it one more time, I can',
|
184
|
-
},
|
185
|
-
],
|
160
|
+
id: 'identifier',
|
161
|
+
links: {
|
162
|
+
about: nil,
|
163
|
+
documentation: nil,
|
164
|
+
},
|
165
|
+
status: 'flibbity',
|
166
|
+
code: 'jibbit',
|
167
|
+
title: 'roll dem bones and stones',
|
168
|
+
detail: 'I cannot receive any satisfaction',
|
169
|
+
source: 'But perhaps if I attempt it one more time, I can',
|
186
170
|
)
|
187
171
|
end
|
188
172
|
end
|
@@ -51,33 +51,41 @@ RSpec.describe ResourcePersistenceError do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'includes the resource name and action in the source' do
|
54
|
-
error = ResourcePersistenceError.new
|
55
|
-
|
54
|
+
error = ResourcePersistenceError.new pointer: '/data/pointer/stuff',
|
55
|
+
attribute: 'my_attribute',
|
56
|
+
value: 'my_value'
|
56
57
|
|
57
|
-
expect(error.source).to eql('
|
58
|
-
'
|
58
|
+
expect(error.source).to eql('pointer' => '/data/pointer/stuff',
|
59
|
+
'parameter' => 'my_attribute',
|
60
|
+
'value' => 'my_value')
|
59
61
|
end
|
60
62
|
|
61
63
|
it 'can convert an "ActiveRecord::RecordNotSaved"' do
|
62
64
|
record = ErratumTestModel.new
|
63
65
|
record.valid?
|
64
66
|
resource_persistence_error = ActiveRecord::RecordNotSaved.new('message', record)
|
65
|
-
|
67
|
+
errors = ResourcePersistenceError.
|
66
68
|
convert(resource_persistence_error)
|
69
|
+
error = errors.first
|
67
70
|
|
68
|
-
expect(error.
|
69
|
-
expect(error.
|
71
|
+
expect(error.pointer).to eql '/data/attributes/some_attribute'
|
72
|
+
expect(error.attribute).to eql 'someAttribute'
|
73
|
+
expect(error.value).to eql ''
|
74
|
+
expect(error.detail).to eql "Some attribute can't be blank"
|
70
75
|
end
|
71
76
|
|
72
77
|
it 'can convert an "ActiveRecord::RecordInvalid"' do
|
73
78
|
record = ErratumTestModel.new
|
74
79
|
record.valid?
|
75
80
|
resource_persistence_error = ActiveRecord::RecordInvalid.new(record)
|
76
|
-
|
81
|
+
errors = ResourcePersistenceError.
|
77
82
|
convert(resource_persistence_error)
|
83
|
+
error = errors.first
|
78
84
|
|
79
|
-
expect(error.
|
80
|
-
expect(error.
|
85
|
+
expect(error.pointer).to eql '/data/attributes/some_attribute'
|
86
|
+
expect(error.attribute).to eql 'someAttribute'
|
87
|
+
expect(error.value).to eql ''
|
88
|
+
expect(error.detail).to eql "Some attribute can't be blank"
|
81
89
|
end
|
82
90
|
end
|
83
91
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erratum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thegranddesign
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
zRIv8lqQM8QFT76rzP5SBCERwN+ltKAFbQ5/FwmZNGWYnmCP3RZMQiRnbh+9H9lh
|
32
32
|
mlbwaYZTjgsXq6cy8N38EecewgBbZYS1IYJraE/M
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2016-05-
|
34
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
metadata.gz.sig
CHANGED
Binary file
|