lhs 6.8.1 → 6.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs/errors.rb +27 -10
- data/lib/lhs/version.rb +1 -1
- data/spec/item/errors_spec.rb +38 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5393d4f50916acb89d04bb7aa7e5576c44d3663
|
4
|
+
data.tar.gz: ff323966be871eda309fef270baf401bb66c8b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80e80735fb752b92f5f4e3f3545148283a396a322e24f583ce3e1504d106b40b9b89c8b4dfccdac4c6ef3045df6e700a41342827005d3e6659009bb96467e12f
|
7
|
+
data.tar.gz: ff0c3bec571ca7772222b66cee22d652be6927a1c62083959487cb94be1a989024b8296919fd1ef859b96c82625c2a6175f85e97f37bfe3d46c084ea5c7a5f8b
|
data/lib/lhs/errors.rb
CHANGED
@@ -8,7 +8,8 @@ class LHS::Errors
|
|
8
8
|
@messages = messages_from_response(response)
|
9
9
|
@message = message_from_response(response)
|
10
10
|
@raw = response.body if response
|
11
|
-
rescue JSON::ParserError
|
11
|
+
rescue JSON::ParserError
|
12
|
+
add_error(messages, 'body', 'parse error')
|
12
13
|
end
|
13
14
|
|
14
15
|
def include?(attribute)
|
@@ -65,25 +66,41 @@ class LHS::Errors
|
|
65
66
|
private
|
66
67
|
|
67
68
|
def add_error(messages, key, value)
|
69
|
+
key = key.to_sym
|
68
70
|
messages[key] ||= []
|
69
71
|
messages[key].push(value)
|
70
72
|
end
|
71
73
|
|
72
74
|
def parse_messages(json)
|
73
75
|
messages = {}
|
74
|
-
if json['fields']
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
fields_to_errors(json, messages) if json['fields']
|
77
|
+
field_errors_to_errors(json, messages) if json['field_errors']
|
78
|
+
fallback_errors(json, messages) if messages.empty?
|
79
|
+
messages
|
80
|
+
end
|
81
|
+
|
82
|
+
def fallback_errors(json, messages)
|
83
|
+
if json.present?
|
84
|
+
json.each do |key, value|
|
85
|
+
add_error(messages, key, value)
|
79
86
|
end
|
87
|
+
else
|
88
|
+
add_error(messages, 'unknown', 'error')
|
80
89
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
90
|
+
end
|
91
|
+
|
92
|
+
def field_errors_to_errors(json, messages)
|
93
|
+
json['field_errors'].each do |field_error|
|
94
|
+
add_error(messages, field_error['path'].join('.').to_sym, field_error['code'])
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def fields_to_errors(json, messages)
|
99
|
+
json['fields'].each do |field|
|
100
|
+
field['details'].each do |detail|
|
101
|
+
add_error(messages, field['name'].to_sym, detail['code'])
|
84
102
|
end
|
85
103
|
end
|
86
|
-
messages
|
87
104
|
end
|
88
105
|
|
89
106
|
def messages_from_response(response = nil)
|
data/lib/lhs/version.rb
CHANGED
data/spec/item/errors_spec.rb
CHANGED
@@ -39,6 +39,13 @@ describe LHS::Item do
|
|
39
39
|
}
|
40
40
|
end
|
41
41
|
|
42
|
+
let(:not_defined_error_format) do
|
43
|
+
{
|
44
|
+
'error' => 'missing_token',
|
45
|
+
'error_description' => 'Bearer token is missing'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
42
49
|
before(:each) do
|
43
50
|
LHC.config.placeholder(:datastore, datastore)
|
44
51
|
class Record < LHS::Record
|
@@ -56,6 +63,7 @@ describe LHS::Item do
|
|
56
63
|
result = record.save
|
57
64
|
expect(result).to eq false
|
58
65
|
expect(record.errors).to be
|
66
|
+
expect(record.errors.any?).to eq true
|
59
67
|
expect(record.name).to eq 'Steve'
|
60
68
|
expect(record.errors.include?(:ratings)).to eq true
|
61
69
|
expect(record.errors.include?(:recommended)).to eq true
|
@@ -71,6 +79,7 @@ describe LHS::Item do
|
|
71
79
|
result = record.save
|
72
80
|
expect(result).to eq false
|
73
81
|
expect(record.errors).to be
|
82
|
+
expect(record.errors.any?).to eq true
|
74
83
|
expect(record.errors.include?(:gender)).to eq true
|
75
84
|
expect(record.errors.include?(:"contract.entry_id")).to eq true
|
76
85
|
expect(record.errors[:gender]).to eq ['UNSUPPORTED_PROPERTY_VALUE', 'INCOMPLETE_PROPERTY_VALUE']
|
@@ -85,10 +94,39 @@ describe LHS::Item do
|
|
85
94
|
record = Record.build
|
86
95
|
record.save
|
87
96
|
expect(record.errors.raw).to be
|
97
|
+
expect(record.errors.any?).to eq true
|
88
98
|
json = JSON.parse(record.errors.raw)
|
89
99
|
expect(json['status']).to be
|
90
100
|
expect(json['message']).to be
|
91
101
|
expect(json['field_errors']).to be
|
92
102
|
end
|
93
103
|
end
|
104
|
+
|
105
|
+
context 'request fails with unformated error message' do
|
106
|
+
it 'still tells us that there is an error' do
|
107
|
+
stub_request(:post, "#{datastore}/feedbacks")
|
108
|
+
.to_return(status: 400, body: not_defined_error_format.to_json)
|
109
|
+
record = Record.build
|
110
|
+
record.name = 'Steve'
|
111
|
+
result = record.save
|
112
|
+
expect(result).to eq false
|
113
|
+
expect(record.errors).to be
|
114
|
+
expect(record.errors.any?).to eq true
|
115
|
+
expect(record.errors['error']).to eq ['missing_token']
|
116
|
+
expect(record.errors['error_description']).to eq ['Bearer token is missing']
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'empty error response body' do
|
121
|
+
it 'still tells us that there is an error' do
|
122
|
+
stub_request(:post, "#{datastore}/feedbacks").to_return(status: 400)
|
123
|
+
record = Record.build
|
124
|
+
record.name = 'Steve'
|
125
|
+
result = record.save
|
126
|
+
expect(result).to eq false
|
127
|
+
expect(record.errors).to be
|
128
|
+
expect(record.errors.any?).to eq true
|
129
|
+
expect(record.errors['body']).to eq ['parse error']
|
130
|
+
end
|
131
|
+
end
|
94
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.8.
|
4
|
+
version: 6.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|