taxjar-ruby 2.6.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,7 +28,12 @@ module Taxjar
28
28
  def perform
29
29
  options_key = [:get, :delete].include?(@request_method) ? :params : :json
30
30
  response = build_http_client.request(request_method, uri.to_s, options_key => @options)
31
- response_body = symbolize_keys!(response.parse)
31
+ response_body =
32
+ begin
33
+ symbolize_keys!(response.parse(:json))
34
+ rescue JSON::ParserError
35
+ nil
36
+ end
32
37
  fail_or_return_response_body(response.code, response_body)
33
38
  end
34
39
 
@@ -74,6 +79,7 @@ module Taxjar
74
79
  end
75
80
 
76
81
  def extract_error(code, body)
82
+ return Taxjar::Error.for_json_parse_error(code) if body.nil?
77
83
  klass = Taxjar::Error::ERRORS[code]
78
84
  if !klass.nil?
79
85
  klass.from_response(body)
@@ -61,6 +61,10 @@ module Taxjar
61
61
  new(message, code)
62
62
  end
63
63
 
64
+ def for_json_parse_error(code)
65
+ ServerError.new("Couldn't parse response as JSON.", code)
66
+ end
67
+
64
68
  end
65
69
 
66
70
  def initialize(message = '', code = nil)
@@ -10,7 +10,7 @@ module Taxjar
10
10
  end
11
11
 
12
12
  def patch
13
- 0
13
+ 1
14
14
  end
15
15
 
16
16
  def pre
@@ -168,6 +168,17 @@ describe Taxjar::API::Request do
168
168
  end
169
169
  end
170
170
 
171
+ it 'handles unexpected Content-Type responses' do
172
+ stub_request(:get, "https://api.taxjar.com/api_path").
173
+ with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
174
+ 'Host'=>'api.taxjar.com',
175
+ 'User-Agent'=>"TaxjarRubyGem/#{Taxjar::Version.to_s}"}).
176
+ to_return(:status => 200, :body => 'Something unexpected',
177
+ :headers => {content_type: 'text/html; charset=UTF-8'})
178
+
179
+ expect{subject.perform}.to raise_error(Taxjar::Error::ServerError)
180
+ end
181
+
171
182
  Taxjar::Error::ERRORS.each do |status, exception|
172
183
  context "when HTTP status is #{status}" do
173
184
  it "raises #{exception}" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taxjar-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TaxJar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-09 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable