Skip to content

Commit

Permalink
Bugfix parse body (#359)
Browse files Browse the repository at this point in the history
* remove lonely operator

* raise error if body is nil
  • Loading branch information
ipc103 authored and choran committed Oct 16, 2017
1 parent 0830714 commit 3cea877
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/intercom/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def parse_body(decoded_body, response)
rescue JSON::ParserError => _
raise_errors_on_failure(response)
end
raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body&['type'] == 'error.list'
raise_errors_on_failure(response) if parsed_body.nil?
raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list'
parsed_body
end

Expand Down
12 changes: 6 additions & 6 deletions spec/unit/intercom/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
proc {req.parse_body('<html>somethjing</html>', response)}.must_raise(Intercom::RateLimitExceeded)
end

it 'parse_body raises an error if the decoded_body is "null"' do
response = OpenStruct.new(:code => 500)
req = Intercom::Request.new('path/', 'GET')
proc { req.parse_body('null', response)}.must_raise(Intercom::ServerError)
end

describe 'Intercom::Client' do
let (:client) { Intercom::Client.new(token: 'foo', handle_rate_limit: true) }
let (:uri) {"https://api.intercom.io/users"}
Expand Down Expand Up @@ -62,10 +68,4 @@
req = Intercom::Request.new('path/', 'GET')
assert_nil(req.parse_body(nil, response))
end

it 'parse_body returns nil if the decoded_body is "null"' do
response = OpenStruct.new(:code => 500)
req = Intercom::Request.new('path/', 'GET')
req.parse_body('null', response).must_equal(nil)
end
end

0 comments on commit 3cea877

Please sign in to comment.