faraday-client_error_handling 0.0.2 → 0.0.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1498ad2458223369fdfe123da8c2b5725eff5aa
|
4
|
+
data.tar.gz: dc16f39b2544edac98e3229e0f5e335210a18a71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b19a0262b62a4243d2f7103befde1bcc0f44e224585d9727ad38b9ec0bb7390b62e70c312e51ec039ba822e93a4176d1c53ab1c81d71e0405380de8a80b790bc
|
7
|
+
data.tar.gz: 1d01464ceadba73d2965f05dc4dc4fc838b24eb071ac765283ce18fb7e9da4dd628cbe480cfa962a508ece2ae7b3b9471c75feab20d2faa7cdcebf1f71ab6a86
|
@@ -2,20 +2,28 @@ module Faraday
|
|
2
2
|
module ClientErrorHandling
|
3
3
|
class Parser < Faraday::Response::Middleware
|
4
4
|
def on_complete(env)
|
5
|
-
|
5
|
+
if env[:body].size == 0
|
6
|
+
env[:body] = {
|
7
|
+
data: {},
|
8
|
+
errors: {},
|
9
|
+
metadata: {}
|
10
|
+
}
|
11
|
+
else
|
12
|
+
json = MultiJson.load(env[:body], symbolize_keys: true)
|
6
13
|
|
7
|
-
|
14
|
+
errors = json.delete(:errors) || {}
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
if defined?( Rails ) && !errors.empty?
|
17
|
+
Rails.logger.warn "SERVICE ERRORS: #{errors}"
|
18
|
+
end
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
metadata = json.delete(:metadata) || {}
|
21
|
+
env[:body] = {
|
22
|
+
data: json,
|
23
|
+
errors: errors,
|
24
|
+
metadata: metadata
|
25
|
+
}
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
@@ -4,9 +4,9 @@ class Rails
|
|
4
4
|
end
|
5
5
|
|
6
6
|
describe Faraday::ClientErrorHandling::Parser do
|
7
|
-
|
8
|
-
parser = Faraday::ClientErrorHandling::Parser.new
|
7
|
+
let(:parser) { Faraday::ClientErrorHandling::Parser.new }
|
9
8
|
|
9
|
+
it 'logs errors in Rails land' do
|
10
10
|
logger = double('Rails logger')
|
11
11
|
expect(logger).to receive(:warn)
|
12
12
|
|
@@ -23,4 +23,17 @@ describe Faraday::ClientErrorHandling::Parser do
|
|
23
23
|
|
24
24
|
parser.on_complete(env)
|
25
25
|
end
|
26
|
+
|
27
|
+
it 'handles head responses' do
|
28
|
+
env = Hash.new
|
29
|
+
env[:body] = ''
|
30
|
+
parser.on_complete(env)
|
31
|
+
|
32
|
+
expect(env[:body]).to eq({
|
33
|
+
data: {},
|
34
|
+
errors: {},
|
35
|
+
metadata: {}
|
36
|
+
})
|
37
|
+
|
38
|
+
end
|
26
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-client_error_handling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|