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: e41fa10ec11afe25ed9889c06b9bb2cd363bb94a
4
- data.tar.gz: da41aad11e5618ef5aa929693a559a0b4c464c57
3
+ metadata.gz: d1498ad2458223369fdfe123da8c2b5725eff5aa
4
+ data.tar.gz: dc16f39b2544edac98e3229e0f5e335210a18a71
5
5
  SHA512:
6
- metadata.gz: bbcd9197ad06dff73a721b73e850f3fbe81867ebea0e4cf92dc1575323c1210365ed2bced9466efb62cb3d3374f3bb33946f40ff626bbd955c63691901a5d88c
7
- data.tar.gz: 65e1f89f20ac41155f6c5c6e78b24c106d04494a19f4a0941e28e8d3266152dbb4f58f8afaf88d01cd6bd34da04dbdde16cf66388e68018e14bee65bb8223ba7
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
- json = MultiJson.load(env[:body], symbolize_keys: true)
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
- errors = json.delete(:errors) || {}
14
+ errors = json.delete(:errors) || {}
8
15
 
9
- if defined?( Rails ) && !errors.empty?
10
- Rails.logger.warn "SERVICE ERRORS: #{errors}"
11
- end
16
+ if defined?( Rails ) && !errors.empty?
17
+ Rails.logger.warn "SERVICE ERRORS: #{errors}"
18
+ end
12
19
 
13
- metadata = json.delete(:metadata) || {}
14
- env[:body] = {
15
- data: json,
16
- errors: errors,
17
- metadata: metadata
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
@@ -1,5 +1,5 @@
1
1
  module Faraday
2
2
  module ClientErrorHandling
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -4,9 +4,9 @@ class Rails
4
4
  end
5
5
 
6
6
  describe Faraday::ClientErrorHandling::Parser do
7
- it 'logs errors in Rails land' do
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.2
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-09-25 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday