Skip to content

Commit 3cea877

Browse files
ipc103choran
authored andcommitted
Bugfix parse body (#359)
* remove lonely operator * raise error if body is nil
1 parent 0830714 commit 3cea877

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/intercom/request.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def parse_body(decoded_body, response)
100100
rescue JSON::ParserError => _
101101
raise_errors_on_failure(response)
102102
end
103-
raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body&['type'] == 'error.list'
103+
raise_errors_on_failure(response) if parsed_body.nil?
104+
raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list'
104105
parsed_body
105106
end
106107

spec/unit/intercom/request_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
proc {req.parse_body('<html>somethjing</html>', response)}.must_raise(Intercom::RateLimitExceeded)
1717
end
1818

19+
it 'parse_body raises an error if the decoded_body is "null"' do
20+
response = OpenStruct.new(:code => 500)
21+
req = Intercom::Request.new('path/', 'GET')
22+
proc { req.parse_body('null', response)}.must_raise(Intercom::ServerError)
23+
end
24+
1925
describe 'Intercom::Client' do
2026
let (:client) { Intercom::Client.new(token: 'foo', handle_rate_limit: true) }
2127
let (:uri) {"https://api.intercom.io/users"}
@@ -62,10 +68,4 @@
6268
req = Intercom::Request.new('path/', 'GET')
6369
assert_nil(req.parse_body(nil, response))
6470
end
65-
66-
it 'parse_body returns nil if the decoded_body is "null"' do
67-
response = OpenStruct.new(:code => 500)
68-
req = Intercom::Request.new('path/', 'GET')
69-
req.parse_body('null', response).must_equal(nil)
70-
end
7171
end

0 commit comments

Comments
 (0)